SQL 错误:查询已超时 或者 查询其他表正常,但指定某个表一直显示"正在执行中..."

SQL 错误:查询已超时  或者 查询其他表正常,但指定某个表一直显示"正在执行中..."

解决方法:先通过 查询 阻塞/死锁 的进程模块,找到进程ID,然后杀死 阻塞/死锁 的进程

1、查询

方法1:

select * from sys.sysprocesses where blocked<>0

方法2:

use master
go
select spid, blocked, loginame, last_batch, status, cmd, hostname, program_name from sysprocesses
where spid in ( select blocked from sysprocesses where blocked <> 0 ) or (blocked <>0)

方法3:

declare 
  @spid int,
  @bl int
DECLARE s_cur CURSOR FOR   
select  0 ,blocked   from (select * from sys.sysprocesses where  blocked>0 ) a
where not exists(select * from (select * from sys.sysprocesses where  blocked>0 ) b   where a.blocked=spid)
union
select spid,blocked from sys.sysprocesses where  blocked>0   OPEN s_cur   FETCH NEXT FROM s_cur INTO @spid,@bl   WHILE @@FETCH_STATUS = 0
begin   
  if @spid =0
    select ' 引起死锁的是: '+ CAST(@bl AS VARCHAR(10)) + ' 进程号, 其执行的SQL 语法如下'   
  else
    select ' 进程号SPID :'+ CAST(@spid AS VARCHAR(10))+ ' 被' + ' 进程号SPID :'+ CAST(@bl AS VARCHAR(10)) +' 阻塞, 其当前进程执行的SQL 语法如下'
DBCC INPUTBUFFER (@bl )   FETCH NEXT FROM s_cur INTO @spid,@bl   
end   
CLOSE s_cur
DEALLOCATE s_cur

2、解决( kill  spid(进程号) 

例如:

kill 56

  

 

  

 

 

创建时间:2021.10.18  更新时间:

 

posted on 2021-10-18 17:07  滔Roy  阅读(338)  评论(0编辑  收藏  举报

导航