How To Create, Rename, Delete (Drop) A Database In MS Sql (Part 3/3)
For Deleting a database, Right Click on the database and select Delete.
A new window will come as shown below.
Check the Close Existing Connections and Click OK Button.
By this way we can Delete a database usng Management Studio.
For Deleting a databse use the following code.
Alter Command looks likes as follows
Drop database CurrentDatabaseName.
If the database is used by some other process, the Delete will not happen.
First of all close all connections to the database and then do the delete operation.
If the database is in use, just follow these steps.
1. Make the Database in Single User Mode.
2. If any transation is happening now, just Rollback them.
The following code do the above two functions.
Alter Database DatabaseName Set SINGLE_USER With Rollback Immediate.
By Executing the above code, we can Delete the Database without having any Error Message.