---查死锁
select CONVERT(VARCHAR(100), request_session_id) spid
,OBJECT_NAME(resource_associated_entity_id) tableName
from sys.dm_tran_locks where resource_type='OBJECT'
---批量解死锁
DECLARE @sql VARCHAR(1000)
DECLARE @spid VARCHAR(36)
DECLARE BLBL_CURSOR CURSOR
FOR
select CONVERT(VARCHAR(100), request_session_id) spid
from sys.dm_tran_locks where resource_type='OBJECT'
OPEN BLBL_CURSOR;
FETCH NEXT FROM BLBL_CURSOR
INTO @spid
WHILE @@FETCH_STATUS = 0
BEGIN
PRINT '@spid ='+@spid
set @sql='kill '+cast(@spid as varchar)
exec(@sql)
FETCH NEXT FROM BLBL_CURSOR INTO @spid
END;
CLOSE BLBL_CURSOR;
DEALLOCATE BLBL_CURSOR;