首先创建一个标量值函数DigLock,用来递归检测SqlServer中的每一个会话是否存在加锁循环,如果该函数最终返回1则表示检测到了加锁循环 (也就是说检测到了死锁),如果最终返回0则表示没有检测到加锁循环. CREATE FUNCTION [dbo].[DigLock] ( @spid int, @orginSpid int ) RETURNS bit AS BEGIN declare @blockedSpid int=null; and blocked=@spid if @blockedS…
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_who_lock]') and ) drop procedure [dbo].[sp_who_lock] GO use master go create procedure sp_who_lock as begin declare @spid int,@bl int, @intTransactionCountOnEntry int, @intRowco…
SET @sql = ' SET TRANSACTION ISOLATION LEVEL REPEATABLE READ; SET DEADLOCK_PRIORITY 10 BEGIN TRAN DECLARE @QuestionList TABLE(ID BIGINT,StudentCode NVARCHAR(50)) INSERT INTO @QuestionList(ID,StudentCode) SELECT TOP ))+' SS.ID,SS.StudentCode FROM ['+@…
USE mastergo CREATE PROCEDURE [dbo].[sp_who_lock]AS BEGIN DECLARE @spid INT , @bl INT , @intTransactionCountOnEntry INT , @intRowcount INT , @intCountProperties INT , @intCounter INT C…