sp_who 查找 blk 引起死锁的Spid
引起死锁的SQL语句
SELECT SDEC.[most_recent_sql_handle], DEST.[text]
FROM sys.[dm_exec_connections] SDEC
CROSS APPLY sys.[dm_exec_sql_text](SDEC.[most_recent_sql_handle]) AS DEST
WHERE SDEC.[most_recent_session_id] = spid
Kill Spid
引起死锁的SQL语句
SELECT SDEC.[most_recent_sql_handle], DEST.[text]
FROM sys.[dm_exec_connections] SDEC
CROSS APPLY sys.[dm_exec_sql_text](SDEC.[most_recent_sql_handle]) AS DEST
WHERE SDEC.[most_recent_session_id] = spid
Kill Spid
SqlServer经常因为某些语句或事物的误操作造成死锁。
查询导致死锁的表和进程ID:
- select
- request_session_id spid,
- OBJECT_NAME(resource_associated_entity_id) tableName
- from
- sys.dm_tran_locks
- where
- resource_type='OBJECT
杀掉死锁:
- kill spid