chenwolong
-- 查询死锁
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 

这样就解除了死锁

@陈卧龙的博客

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-10
  • 2021-11-21
  • 2022-02-28
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-02-27
  • 2021-08-02
  • 2022-12-23
  • 2021-12-21
  • 2021-12-10
相关资源
相似解决方案