Kill all processes for specific database on Microsoft SQL Server

Problem:

How to kill all processes on Microsoft SQL Server database ?

Solution:

Applied to: Microsoft SQL Server

Execute the follow query on master database and change ‘MyDB’ with your DB:

DECLARE @kill varchar(8000) = ”;
SELECT @kill = @kill + ‘kill ‘ + CONVERT(varchar(5), spid) + ‘;’
FROM master..sysprocesses
WHERE dbid = db_id(‘MyDB’)
EXEC(@kill);

Best Regards,

ITquadro – specialized Blog

ITquadro consulenti informatici specializzati in ambienti microsoft windows server 2008 R2 e Microsoft Windows Server 2012. Ci trovate su Bologna ed Emilia-Romagna ma anche su Milano e Roma.
Siamo un’azienda di consulenza informatica a Bologna