ref:http://blog.csdn.net/wsh236/article/details/4296875

use master 
go 

declare @dbname sysname 
set @dbname='DB1' --这个是要删除的数据库库名 

declare @s nvarchar(1000) 
declare tb cursor local for 
select s='kill '+cast(spid as varchar) 
from master..sysprocesses 
where dbid=db_id(@dbname) 

open tb 
fetch next from tb into @s 
while @@fetch_status=0 
begin 
exec(@s) 
fetch next from tb into @s 
end 
close tb 
deallocate tb 
exec('drop database ['+@dbname+']')  

 

转载于:https://www.cnblogs.com/SpringSmallGrass/archive/2013/04/27/3046831.html

Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐