殺死所有的指定資料庫的程式的儲存過程

kitesky發表於2006-12-11

declare @spt table (spid int)
declare @spid int , @sql varchar(255)

insert into @spt
select spid --, kpid, waittype, waittime, lastwaittype, dbid, status, cmd, hostname, loginame, program_name
from master.dbo.sysprocesses
where dbid = db_id('YourDBName')
and spid <> @@spid

declare cur_spid cursor for
select spid from @spt
open cur_spid

while @@FETCH_STATUS = 0
begin
fetch next from cur_spid into @spid
set @sql = 'kill '+ cast( @spid as varchar )
exec (@sql)
end

close cur_spid
deallocate cur_spid
go

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/66009/viewspace-883312/,如需轉載,請註明出處,否則將追究法律責任。

相關文章