DECLARE @spid INT , @bl INT , @intTransactionCountOnEntry INT , @intRowcount INT , @intCountProperties INT , @intCounter INT CREATE TABLE#tmp_lock_who (IDINT IDENTITY(1,1), spidSMALLINT, BLSMALLINT ) IF @ @ERROR <> 0 Print @ @ERROR INSERT into#tmp_lock_who (spid, BL)SELECT 0, blocked from(SELECT * fromMaster.. sysprocessesWHEREBlocked> 0) AWHERE not EXISTS(SELECT * from(SELECT * fromMaster.. sysprocessesWHEREBlocked> 0) bWHEREA.blocked=spid)UNION SELECTspid, blocked fromMaster.. sysprocessesWHEREBlocked> 0 IF @ @ERROR <> 0 Print @ @ERROR--number of records found for temporary table SELECT @intCountProperties = COUNT(*) , @intCounter = 1 from#tmp_lock_whoIF @ @ERROR <> 0 Print @ @ERROR IF @intCountProperties = 0 SELECT 'No blocking and deadlock information now' asmessage--Cycle Start while @intCounter <= @intCountProperties BEGIN--take the first record SELECT @spid =spid,@bl =BL from#tmp_lock_whoWHEREId= @intCounter BEGIN IF @spid = 0 SELECT 'causing the database to be slow is:' + CAST(@bl as VARCHAR(Ten)) + 'process number, which executes the following SQL syntax' ELSE SELECT 'process number spid:' + CAST(@spid as VARCHAR(Ten))+ 'was' + 'process number spid:' + CAST(@bl as VARCHAR(Ten)) + 'The SQL syntax that the current process executes is blocked as follows' DBCCInputBuffer (@bl ) END--The loop pointer moves down SET @intCounter = @intCounter + 1 END DROP TABLE#tmp_lock_whoPrint 0
SQL database Query the current environment has no deadlock