----- 建立死結查詢 USEmaster; GO DROPPROCEDURE sp_who_lock GO createprocedure sp_who_lock as begin declare @spid int,@bl int, @intTransactionCountOnEntry int, @intRowcount int, @intCountProperties int, @intCounter int createtable#tmp_lock_who ( idintidentity(1,1), spid smallint, bl smallint)
IF @@ERROR<>0RETURN @@ERROR
INSERTINTO#tmp_lock_who (spid, bl) SELECT 0 ,blocked FROM (SELECT * FROM sysprocesses WHERE blocked > 0) a WHERENOTEXISTS (SELECT * FROM (SELECT * FROM sysprocesses WHERE blocked > 0) b WHERE a.blocked = spid) UNIONSELECT spid ,blocked FROM sysprocesses WHERE blocked > 0 IF @@ERROR <> 0 RETURN @@ERROR