"無法刪除數據庫,因為該數據庫當前正在使用"問題解決


use master   
go  
      
declare @dbname sysname   
set @dbname = 'chhai' --這個是要刪除的數據庫庫名   
/*****用游標殺死進程*****/ 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 + ']')

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM