Sql Server: ALTER DATABASE SET SINGLE_USER WITH ROLLBACK IMMEDIATE
- Posted by Sqltimes
- On August 23, 2013
- 0 Comments
A quick one:
In my lab environment, I burn through a good set of databases frequently. I create a new one, play with it for the task needed; When done, DROP it. Sometimes the ‘DROP DATABASE’ command fails with this reason.
Msg 3702, Level 16, State 4, Line 1 Cannot drop database "DBADB" because it is currently in use.
Since this is a lab environment and no ones else has access to it, I could take some drastic steps to DROP it.
Example:
1
2
3
4
5
6
7
8
9
|
ALTER DATABASE DBADB SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO DROP DATABASE [DBADB] GO |
Bingo !! The database goes into SINGLE USER mode and I can quickly DROP it.
Note: Please do not try this on Production; This is just a hack for lab environment databases.
Hope this helps,
_Sqltimes
0 Comments