How to kill all sql processes in database

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

Popular posts from this blog

How to Convert Word Document to PDF using C#

How to Implement a Simple Chatbot Using ChatGPT in a C# WinForms Application?

Sql query to get counts by quarterly and half yearly