use master
declare @dbname sysname
set @dbname=N'要断开连接的库名'
declare hCForEach cursor global for select 'kill '+rtrim(spid) from sysprocesses where dbid=db_id(@dbname)
exec sp_msforeach_worker '?'
use master
declare @spid int,@str varchar(100),@dbid int,@dbname varchar(255)
set @dbname='yl2004' --Replace with you Database Name,try it
select @dbid=dbid from master.dbo.sysdatabases WHERE name = @dbname
declare cur_spid cursor local for
select spid from master.dbo.sysprocesses where dbid=@dbid
open cur_spid
fetch from cur_spid into @spid
while @@fetch_status=0
begin
set @str='kill '+Cast(@spid as varchar(10))
exec(@str)
fetch from cur_spid into @spid
end
close cur_spid
deallocate cur_spid