use master
GO
CREATE PROC support_KillBlockingProcesses (@RecursiveCount int = NULL)
AS
DECLARE @count int, @spid int, @sql nvarchar(max)
SET @count = ISNULL(@RecursiveCount, 3)
while @count > 0
begin
begin try
set @spid = (
select top 1 spid from sysprocesses (nolock)
where blocked = 0 and spid in (
select blocked from sysprocesses (nolock) where blocked <> 0
)
)
if @spid > 50
begin
set @sql = N'kill ' + cast(@spid as nvarchar(100))
exec sp_executesql @sql
--print @sql
end
end try
begin catch
--print 'error'
end catch
set @count = @count - 1
end
GO
I saw this stored procedure, and I am wondering if there's any danger of running this stored process whenever the db is frozen. My thought process is that you still need to kill the blocking process even if the process you kill is important, so is there really any consequence of doing this? And what's the point of knowing which process is freezing up the db?