declare @spid int,@bl int
DECLARE s_cur CURSOR FOR
select 0 ,blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
union select spid,blocked from sysprocesses where blocked>0
OPEN s_cur
FETCH NEXT FROM s_cur INTO @spid,@bl
WHILE @@FETCH_STATUS = 0
begin
if @spid =0
select N'引起數據庫死鎖的是:
'+ CAST(@bl AS VARCHAR(10)) + N'進程號,其執行的SQL語法如下'
else
select N'進程號SPID:'+ CAST(@spid AS VARCHAR(10))+ N'被進程號SPID:'+ CAST(@bl AS VARCHAR(10)) +N'阻塞,其當前進程執行的SQL語法如下'
DBCC INPUTBUFFER (@bl )
FETCH NEXT FROM s_cur INTO @spid,@bl
end
CLOSE s_cur
DEALLOCATE s_cur
刪除 procedure
Kill XXX