【sqlserver】殺掉所有死鎖程式

renjixinchina發表於2012-08-31
DECLARE
@USER_ID INT, @KILLCMD VARCHAR(100)
-- 根據選擇條件,選擇出應該取消的程式
DECLARE cur_lock CURSOR FOR
SELECT spid FROM master..sysprocesses
WHERE
blocked = 0
AND spid IN 
(SELECT blocked FROM master..sysprocesses);
-- 取消所有選擇出的程式。
OPEN cur_lock;
FETCH NEXT FROM cur_lock INTO @USER_ID;
WHILE @@FETCH_STATUS = 0
BEGIN
SET @KILLCMD = 'kill ' + CAST(@USER_ID AS VARCHAR);
EXECUTE (@KILLCMD);
FETCH NEXT FROM cur_lock INTO @USER_ID;
END;
CLOSE cur_lock;
DEALLOCATE cur_lock;

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/15747463/viewspace-742391/,如需轉載,請註明出處,否則將追究法律責任。

相關文章