How to Drop Database by using T-SQL or GUI - SQL Server / T-SQL Tutorial Part 25

Опубликовано: 16 Февраль 2016
на канале: TechBrothersIT
5,328
23

How to Drop Database by using T-SQL or GUI - SQL Server / T-SQL Tutorial

Link to post for scripts
http://www.techbrothersit.com/2016/02...

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.

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.

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.


Check out our website for Different SQL Server, MSBI tutorials and interview questions
such as SQL Server Reporting Services(SSRS) Tutorial
SQL Server Integration Services(SSIS) Tutorial
SQL Server DBA Tutorial
SQL Server / TSQL Tutorial ( Beginner to Advance)
http://www.techbrothersit.com/


Смотрите видео How to Drop Database by using T-SQL or GUI - SQL Server / T-SQL Tutorial Part 25 онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь TechBrothersIT 16 Февраль 2016, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 5,328 раз и оно понравилось 23 людям.