How to Drop Database by using TSQL and GUI - SQL Server / TSQL Tutorial Part 25


You are working as Database developer in Health Insurance company, You need to generate script to drop database that can be used in different environments such as QA, UAT and Production.


There are multiple ways to drop the database in SQL Server. You can use GUI part of SSMS to drop database. 

By using GUI:
Right Click on the database that you would like to drop and then hit Delete as shown below. 

How to Delete Database in SQL Server - SQL Server Tutorial

In below windows, check the checkbox Close existing connections. This will close any existing connections, if you don't check this, the drop might fail if there are open connections to database.
How to drop Database in SQL Server - SQL Server / TSQL Tutorial Step by Step 

Use TSQL To Drop Database in SQL Server:
At this point you can hit Script button in above window to generate script so you can use anytime you like. Once you hit Script and open in new window. Below Script will be create.

USE [master]




USE [master]


The first part of script will set the database to Single User mode and rollback any open transactions immediately. Second Part of script will drop the database.

1 comment:

  1. Numerous illnesses, including neuroses, depression, obsessive-compulsive disorder, and even schizophrenia, are characterized by obsessive thoughts. When these ideas are tried to escape, anxiety attacks and severe discomfort result. A person develops insomnia as a result of ongoing concerns and negative thoughts that keep them from falling asleep. Obsessions can result in despair, social isolation, and psychological tiredness if you delay seeking help. These syndromes can appear in a variety of diseases, thus a highly experienced psychiatrist should make a diagnosis. I suggest beginning . this will enable them to comprehend the subtleties of the clinical picture and the causes of insomnia and obsessive thinking.