欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

MSSQL 死锁和阻塞 查看事务

程序员文章站 2022-06-02 12:25:59
...
declare @spid int      
   declare @blk int      
   declare @count int      
   declare @index int      
   declare @lock tinyint       
   set @lock=0       
   create table #temp_who_lock       
 (       
  id int identity(1,1),       
  spid int,       
  blk int      
 )       
 if @@error<>0 select @@error       
 insert into #temp_who_lock(spid,blk)       
 select 0 ,blocked        
 from (select * from master..sysprocesses where blocked>0)a       
 where not exists(select * from  master..sysprocesses where a.blocked =spid and blocked>0)      
 union select spid,blocked from  master..sysprocesses where blocked>0       
 if @@error<>0 select @@error       
 select @count=count(*),@index=1 from #temp_who_lock       
 if @@error<>0 select @@error       
 if @count=0       
 begin      
  select '没有阻塞和死锁信息'   
 end