Wednesday, October 3, 2012

query to kill all the process [used when restoring the database]


use  master
DECLARE @dbname sysname
SET @dbname = 'DataBase Name'

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

No comments:

Post a Comment