Killing all Sql Server Processes in Database.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 195
Declare @spid varchar(max);
set @spid = Null;
SELECT @spid = COALESCE(@spid +'; Kill ' + ' ','') + CAST(spid AS VARCHAR(10))
FROM master..sysprocesses WHERE dbid = DB_ID('db name')
AND spid != @@SPID

if @spid is not null
set @spid='Kill '+ @spid
print @spid
exec(@spid)
select * FROM master..sysprocesses
WHERE dbid = DB_ID('db name')
AND spid != @@SPID;

Comments or Responses

Login to post response