Remove Database - SQL Server

  1. Before You Begin
  2. Recommendations Recommendations
  3. Using SQL Server Management Studio Using SQL Server Management Studio
  4. Using Transact-SQL Using Transact-SQL
  5. Next steps. After deleting the database, Follow Up: After deleting a database
  6. See also: See Also

APPLICATION AREA: APPLICATION AREA:   SQL Server   Azure SQL Database   Azure SQL Data Warehouse   Parallel Data Warehouse APPLIES TO:   SQL Server   Azure SQL Database   Azure SQL Data Warehouse   Parallel Data Warehouse   This section describes how to delete a user database in SQL Server Management Studio SQL Server Management Studio in SQL Server 2017 SQL Server 2017 using SQL Server Management Studio SQL Server Management Studio or Transact-SQL Transact-SQL SQL Server Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse APPLIES TO: SQL Server Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse

This section describes how to delete a user database in SQL Server Management Studio SQL Server Management Studio in SQL Server 2017 SQL Server 2017 using SQL Server Management Studio SQL Server Management Studio or Transact-SQL Transact-SQL. SQL Server 2017 SQL Server 2017 by SQL Server Management Studio or Transact-SQL Transact-SQL.

In This Section In This Topic

Before You Begin

Limitations and Restrictions Restrictions

  • System databases cannot be deleted. System databases cannot be deleted.

Prerequisites Prerequisites

  • Delete any database snapshots that exist for the database. Delete any database snapshots that exist on the database. For more information, see. Remove Database Snapshot (Transact-SQL) . For more information, see Drop a Database Snapshot (Transact-SQL) .

  • If the database is involved in log shipping, remove the log shipping. If the database is involved in log shipping, remove log shipping.

  • If the database is published for transactional replication, published, or subscribed to merge replication, remove the replication from the database. If the database is published for transactional replication, or has been published or subscribed for merge replication, remove replication from the database.

Recommendations Recommendations

  • Consider the possibility of a full backup of the database. Consider taking a full backup of the database. A deleted database can only be restored using a backup. A deleted database can be created only by restoring a backup.

Security

Permissions Permissions

To execute the DROP DATABASE instruction, the user must at least have CONTROL permission on the database. To execute DROP DATABASE, at a minimum, a minimum of

Using SQL Server Management Studio Using SQL Server Management Studio

Removing a database To delete a database

  1. In Object Explorer, connect to the instance of the SQL Server Database Engine component of the SQL Server Database Engine and deploy it. In the Object Explorer , connect the SQL Server Database Engine to the SQL Server Database Engine, and then expand to the instance.

  2. Expand Databases , right-click the database to be deleted, and then click Remove . Expand Databases , right click the database to delete, and then click Delete .

  3. Confirm that the correct database is selected, and then click OK . Confirm the correct database is selected, and then click OK .

Using Transact-SQL Using Transact-SQL

Removing a database To delete a database

  1. Connect to the Database Engine component of the Database Engine. Connect to the Database Engine Database Engine.

  2. On the Standard panel, click Create Query . From the Standard bar, click New Query .

  3. Copy the following example into the query window and click the Run button. Copy Execute . The following example deletes the Sales and NewSales databases. The example removes the Sales and NewSales databases.

USE master; GO DROP DATABASE Sales, NewSales; GO

Next steps. After deleting the database, Follow Up: After deleting a database

Create a backup of the master database. Back up the master database. If you need to restore the master database, any database deleted since the last backup of the master database was created will remain in the system catalog views and may cause error messages. It has been noted that it has been deleted.

See also: See Also

CREATE DATABASE (SQL Server Transact-SQL) CREATE DATABASE (SQL Server Transact-SQL)
ALTER DATABASE (Transact-SQL) ALTER DATABASE (Transact-SQL)