Method 1
declare @sql as varchar(20), @spid as int
select @spid = min(spid) from master..sysprocesses where dbid = db_id('<database_name>')
and spid != @@spid
while (@spid is not null)
begin
print 'Killing process ' + cast(@spid as varchar) + ' ...'
set @sql = 'kill ' + cast(@spid as varchar)
exec (@sql)
select
@spid = min(spid)
from
master..sysprocesses
where
dbid = db_id('<database_name>')
and spid != @@spid
end
print 'Process completed...'
Method 2
select spid from master..sysprocesses where dbid =db_id('<database_name>') and spid <> @@spid
SELECT *
FROM sys.sysprocesses
WHERE dbid = DB_ID('<database_name>')
declare @sql as varchar(20), @spid as int
select @spid = min(spid) from master..sysprocesses where dbid = db_id('<database_name>')
and spid != @@spid
while (@spid is not null)
begin
print 'Killing process ' + cast(@spid as varchar) + ' ...'
set @sql = 'kill ' + cast(@spid as varchar)
exec (@sql)
select
@spid = min(spid)
from
master..sysprocesses
where
dbid = db_id('<database_name>')
and spid != @@spid
end
print 'Process completed...'
Method 2
select spid from master..sysprocesses where dbid =db_id('<database_name>') and spid <> @@spid
SELECT *
FROM sys.sysprocesses
WHERE dbid = DB_ID('<database_name>')
No comments:
Post a Comment