create proc killspid (@dbname varchar(50))
as
declare @sql nvarchar(1000),@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
exec('kill '+@spid)
fetch next from getspid into @spid
end
close getspid
deallocate getspid
go
--用法
use master
exec killspid '数据库名'