How to find the deadlock reason in sql server ro14?

前端 未结 3 761
天涯浪人
天涯浪人 2021-01-07 03:32

Facing a deadlock in SQL server database and can see deadlock entry in SQL logs. How the log entries can be used to find the reason for this deadlock?

3条回答
  •  无人及你
    2021-01-07 03:51

    This code will display the error log which contains the query that creates the deadlock. IF OBJECT_ID('tempdb.dbo.ErrorLog') IS Not Null BEGIN DROP TABLE tempdb.dbo.ErrorLog END

     CREATE TABLE tempdb.dbo.ErrorLog 
     (Id int IDENTITY (1, 1) NOT NULL, 
      logdate DATETIME, procInfo VARCHAR(10), 
      ERRORLOG VARCHAR(MAX))
    
      -- insert the actual data from the Error log into our newly created table.
    
     INSERT INTO tempdb.dbo.ErrorLog
     EXEC master.dbo.sp_readerrorlog
    
    
    declare @sql nvarchar(max)
    set @sql='select logdate, procInfo, ERRORLOG from tempdb.dbo.ErrorLog 
    where Id >= (select top 1 id  from tempdb.dbo.ErrorLog WHERE ERRORLOG Like 
    ''%deadlock-list%'' order by id desc)'
    select @SQL
    

提交回复
热议问题