用这个,不过那要等数据库连上之后,才能杀掉进程
use master
go
create proc killspid (@dbname varchar(200))
as
begin
declare @sql nvarchar(500),@temp varchar(1000)
declare @spid int
declare getspid cursor for
select spid from sysprocesses where dbid<>db_id(@dbname)
open getspid
fetch next from getspid into @spid
while @@fetch_status =0
begin
set @temp='kill '+rtrim(@spid)
exec(@temp)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
end