& Quot; the database cannot be deleted because the database is currently in use & quot; problem solving. The database is currently

Source: Internet
Author: User

"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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.