/*如果某进程将其他堵塞超过55秒,则自动将其清除,并将其执行的语句报错出来。可将语句建成作业,每分钟执行一次。但有风险,不可作为常规用法,只能在短期内作为捕捉问题的工具,在有跟踪的情况下使用*/ declare @sql nvarchar(4000),@spid int select top 1 @spid = spid from master..sysprocesses a where blocked = 0 and spid in (select blocked from master..sysprocesses where blocked<>0 and waittime > 55000) if @@rowcount=0 return set @sql = 'declare @tbl table(e varchar(2000),pa int,eventinfo varchar(4000)) insert @tbl exec(''dbcc inputbuffer(' + cast(@spid as varchar(10)) + ')'') kill ' + cast(@spid as varchar(10)) + ' declare @msg varchar(4000) select @msg = eventinfo from @tbl set @msg=isnull(@msg,''no sql'') raiserror 50001 @msg' exec(@sql)