DB Scripts – for my own reference

By | August 17, 2016

List of running processes

use master
Select * from master.dbo.sysprocesses
where dbid = db_id(‘DBNAME’)

Killing all processes

Use master
Go

Declare @dbname sysname

Set @dbname = ‘DBNAME’

Declare @spid int
Select @spid = min(spid) from master.dbo.sysprocesses
where dbid = db_id(@dbname)
While @spid Is Not Null
Begin
Execute (‘Kill ‘ + @spid)
Select @spid = min(spid) from master.dbo.sysprocesses
where dbid = db_id(@dbname) and spid > @spid
End

 

Leave a Reply

Your email address will not be published. Required fields are marked *