use master go declare @spid int --查询出死锁的SPID select @spid=blocked from (select * from sysprocesses where blocked>0 ) a where not exists(select * from (select * from sysprocesses where blocked>0 ) b where a.blocked=spid) --输出引起死锁的操作 DBCC INPUTBUFFER (@spid) --exec sp_who2
softwarewander() :select @spid=blocked from (select * from sysprocesses where blocked>0 ) a where not exists(select * from (select * from sysprocesses where blocked>0 ) b where a.blocked=spid)这个语句的意思是,从a里取得blocked的spid,而这个spid不在被阻塞的进程列表中,基本上这个spid就是阻塞的源头(因为它阻塞了别人但自己没被阻塞)KILL是最简单(粗暴)的做法,至于资源分配问题,貌似SQL会自动回收的,还是等待达人的确定性意见吧
go
declare @spid int
--查询出死锁的SPID
select @spid=blocked
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)
--输出引起死锁的操作
DBCC INPUTBUFFER (@spid)
--exec sp_who2
exec (' kill ' + @spid)
查询死锁进程的 sql 语句看不懂, 请教一下
?
from (select * from sysprocesses where blocked>0 ) a
where not exists(select * from (select * from sysprocesses where blocked>0 ) b
where a.blocked=spid)这个语句的意思是,从a里取得blocked的spid,而这个spid不在被阻塞的进程列表中,基本上这个spid就是阻塞的源头(因为它阻塞了别人但自己没被阻塞)KILL是最简单(粗暴)的做法,至于资源分配问题,貌似SQL会自动回收的,还是等待达人的确定性意见吧