DROP DATABASE

Transact-SQL Reference

Transact-SQL Reference

DROP DATABASE

Removes one or more databases from Microsoft® SQL Server™. Removing a database deletes the database and the disk files used by the database.

Syntax

DROP DATABASE database_name [ ,...n ]

Arguments

database_name

Specifies the name of the database to be removed. Execute sp_helpdb from the master database to see a list of databases.

Remarks

To use DROP DATABASE, the database context of the connection must be in the master database.

DROP DATABASE removes damaged databases marked as suspect and removes the specified database. Before dropping a database used in replication, first remove replication. Any database published for transactional replication, or published or subscribed to merge replication cannot be dropped. For more information, see Administering and Monitoring Replication. If a database is damaged and replication cannot first be removed, in most cases you still can drop the database by marking it as an offline database.

A dropped database can be re-created only by restoring a backup. You cannot drop a database currently in use (open for reading or writing by any user). When a database is dropped, the master database should be backed up.

System databases (msdb, master, model, tempdb) cannot be dropped.

Permissions

DROP DATABASE permissions default to the database owner, members of the sysadmin and dbcreator fixed server roles, and are not transferable.

Examples
A. Drop a single database

This example removes all references for the publishing database from the system tables.

DROP DATABASE publishing
B. Drop multiple databases

This example removes all references for each of the listed databases from the system tables.

DROP DATABASE pubs, newpubs

See Also

ALTER DATABASE

CREATE DATABASE

sp_dropdevice

sp_helpdb

sp_renamedb

USE