use tempdb
DECLARE @DBNAME nvarchar(50) = 'TEST' -- имя базы
select
IDENTITY(int, 1,1) as idstr,
t.text as txt,
s.*
into ttemp
from sys.sysprocesses s
cross apply sys.dm_exec_sql_text(s.sql_handle) t
where db_name(s.dbid) = @DBNAME
declare @i int = 0
declare @cou int
declare @spid int = 0
declare @dinsql nvarchar(1000)
set @cou = (select COUNT(*) from ttemp)
while @i <= @cou
begin
set @i = @i + 1
set @spid = (select t.spid from ttemp t where t.idstr = @i)
set @dinsql = 'kill ' + STR(@spid)
begin try
execute(@dinsql)
end try
begin catch
end catch
end
drop table ttemp
Комментариев нет:
Отправить комментарий