无法删除数据库 "#Test",因为该数据库当前正在使用

--查询分析器中执行下面的语句就行了.

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+']')  

相关文章:

  • 2022-02-13
  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-01-22
猜你喜欢
  • 2021-09-10
  • 2021-11-13
  • 2021-09-11
  • 2022-12-23
  • 2021-12-25
  • 2021-08-11
相关资源
相似解决方案