-- 查询死锁 select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type='OBJECT'
杀死死锁进程:
kill spid --例如 kill 354
创造死锁条件:
执行事务锁定表(增删改操作),事务外执行查询操作,模拟死锁
BEGIN TRANSACTION--开始事务 update CM_Code set CodeCount=1 where id='34' WAITFOR DELAY '02:00'; select * from CM_Code where id='34'
执行查询死锁的语句:
select request_session_id spid, OBJECT_NAME(resource_associated_entity_id) tableName from sys.dm_tran_locks where resource_type='OBJECT'
得到如下结果:
执行杀死死锁的加脚本如下:
kill 56
这样就解除了死锁
@陈卧龙的博客