"The database cannot be deleted because the database is currently in use ".
Exception Handling Summary-database http://www.cnblogs.com/dunitian/p/4522990.html Series
I was worried about this problem when I was just learning the database. I saw it again when I deleted it today. I just recorded it together:
Graphical Method:
Command Line Method:
Use master go declare @ dbname sysname set @ dbname = 'bigvaluestest '-- the name of the database to be deleted is 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 +'] ')
This principle is similar to killing the program through pid in the operating system.