MS SQL Server 2012 - DBA Articles

DROP DATABASE - Single and Multiple Databases



DROP DATABASE keywords are used to delete one or more existing user defined databases or snapshots from an instance of SQL Server. SQL Server do not affect source database when delete snapshot database. SELECT * FROM sys.databases query is used to display a list of databases from SQL Server.

When execute DROP DATABASE, SQL Server must run in the autocommit mode and that database should not use means all database user must be disconnect from the database instance of SQL Server. SQL Server deletes only online physical disk files and offline physical disk files should delete through window explorer.

Syntax

DROP DATABASE [ database_name | database_snapshot_name } [,...n] [;]


Example 01

DROP a single Database

The following example is used to delete eEducation database from SQL Server. When execute this T-SQL statement, SQL Server should delete system defined Physical Data File and Log File from HDD.

DROP DATABASE eEducation


Example 02

DROP multiple Databases

The following example is used to delete eEducation_X, eEducation_Y and eEducation_Z databases from SQL Server. When execute this T-SQL statement, SQL Server should delete system defined Physical Data File and Log File from HDD.

DROP DATABASE eEducation_X, eEducation_Y, eEducation_Z


Example 03

DROP a Database Snapshot

The following example is used to delete eEducation_snapshot_05 snapshot database from SQL Server.

DROP DATABASE eEducation_snapshot_05

* * * * *


Email Your Comment To AUTHOR