我正在尝试创建一个 SQL 脚本来杀死所有被阻止的进程。
我错过了什么吗?
declare @max_count int, @count int, @sqlstring varchar(100)
declare @spid_table table (spid int NOT NULL)
INSERT @spid_table
select spid
from master.dbo.sysprocesses
where spid in (select blocked from master.dbo.sysprocesses where blocked > 0)
select @max_count = MAX(spid) FROM @spid_table
select top 1 @count = spid from @spid_table
while @count <= @max_count
begin
select @sqlstring = 'kill ' + CONVERT(varchar(4), @count)
exec(@sqlstring)
end