sql 脚本查看死锁并解锁

-- 查看死锁表

SELECT request_session_id spid,OBJECT_NAME(resource_associated_entity_id) tableName

FROM sys.dm_tran_locks WHERE resource_type = 'object'


--  解锁

DECLARE @spid INT 
SET @spid = 62  -- 解除死锁的spid
DECLARE @sql VARCHAR(1000)
SET @sql = 'kill ' + CAST(@spid AS VARCHAR)
EXEC(@sql)  -- 执行解除死锁

你可能感兴趣的:(sql 脚本查看死锁并解锁)