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

Scenario:

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.

Solution:

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]
GO

ALTER DATABASE [TechBrothersIT]

SET SINGLE_USER
WITH

ROLLBACK IMMEDIATE
GO

USE [master]
GO

DROP DATABASE [TechBrothersIT]
GO

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.


2 comments:

  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 https://us.calmerry.com/try-online-therapy/ . this will enable them to comprehend the subtleties of the clinical picture and the causes of insomnia and obsessive thinking.

    ReplyDelete
  2. If you're experiencing insomnia, you might have tried several things before but have not had significantly success. It is frustrating whenever you want to get good rest but don't wish to risk your quality of life in just about any way.


    The issue is, what else can you do? Today we shall look at a new product that is available and may help you rest greater without endangering your health.


    CBD gummies may be anything really intriguing for individuals to attempt to help them obtain a relaxing sleep. Several pharmaceutical services and products have to contain less than 0.3% of CBD; this is yet another popular substance found in the weed seed, leading to the "high" many people keep company with pot use.


    Nevertheless, it's been shown there are good medicinal effects of CBD. This really is particularly so with the analysis of the influence of reducing nervousness on the capacity to sleep.


    The huge difference between a CBD/ THC fit is that CBD is known as a Routine II medicine, this means it includes a high-potency for managing equally medical and psychological disorders.

    ReplyDelete