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 

这样就解除了死锁

@陈卧龙的博客

分类:

技术点:

相关文章:

  • 2021-10-01
  • 2021-08-28
  • 2021-09-28
  • 2019-07-06
  • 2021-09-28
  • 2019-11-05
  • 2020-03-15
  • 2021-09-28
猜你喜欢
  • 2021-09-28
  • 2018-08-21
  • 2021-04-01
  • 2021-08-17
  • 2021-07-31
  • 2021-09-28
  • 2020-10-19
  • 2020-09-30
相关资源
相似解决方案