SQL 强制删除数据库

use master   
go  
      
declare @dbname sysname   
set @dbname = 'DBDATA'   
      
declare @s nvarchar(1000)   
declare tb cursor local  
for
    select s = 'kill   ' + cast(spid as varchar)
    from   master.dbo.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 + ']') 

猜你喜欢

转载自www.cnblogs.com/zhaoquan/p/10545977.html