Tuesday , November 19 2024

How To Drop a Database in SQL Server

 

In this article, we will talk about two methods to drop a database.

First Method (With SSMS):

When you connect to SQL Server Instance with SQL Server Management Studio, right-click on the database and click Delete.

A screen will appear as follows. On this screen, we uncheck “Delete backup and restore history information for databases” and select “Close existing connections”. Then click OK to delete the database. If there is an active connection in the database, it will be terminated.

Second Method (With TSQL):

If there is no open connection in the database, we can drop the database with the help of the following script.

If there is an open connection in the database, the above script will throw an error as follows.

Msg 3702, Level 16, State 4, Line 7

Cannot drop database “TestDB” because it is currently in use.

 

If you want to drop the database by terminating existing connections, you can do this by using the following script.

Loading

About dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *