SELECT '现在没有阻塞和死锁信息' AS message
-- 循环开始
WHILE @intCounter <= @intCountProperties
BEGIN
-- 取第一条记录
SELECT @spid = spid ,
@bl = bl
FROM #tmp_lock_who
WHERE Id = @intCounter
BEGIN
IF @spid = 0
BEGIN
SELECT '引起数据库死锁的是: ' + CAST(@bl AS VARCHAR(10))
+ '进程号,其执行的SQL语法如下'
END
ELSE
BEGIN
SELECT '进程号SPID:' + CAST(@spid AS VARCHAR(10))
+ '其当前进程执行的SQL语法如下:'
DBCC INPUTBUFFER(@spid)
SELECT '进程号SPID:' + CAST(@spid AS VARCHAR(10)) + '被'
+ '进程号SPID:' + CAST(@bl AS VARCHAR(10))
+ '阻塞,其当前进程执行的SQL语法如下'
END
DBCC INPUTBUFFER (@bl)
END
-- 循环指针下移
SET @intCounter = @intCounter + 1
END
DROP TABLE #tmp_lock_who