Summary: in this tutorial, you will learn how to remove databases using SQL DROP DATABASE statement.
SQL provides DROP DATABASE statement to allow you to remove existing databases. The SQL DROP DATABASE statement deletes all tables, views, triggers, and other related objects inside a database, and also removes the database permanently.
The following illustrates the syntax of the statement:
DROP DATABASE database_name
Some database management systems, such as Microsoft SQL Server or MySQL, allow you to drop multiple databases using a single SQL DROP DATABASE statement. To remove multiple databases, you specify a list of comma-separated database name after the keyword SQL DROP DATABASE as follows:
DROP DATABASE dbname1,dbname2,...
SQL DROP DATABASE Example
Let’s practice with an example to get familiar with SQL DROP TABLE statement.
First, we need to create a new database for practicing purpose. If you don’t know how to create a new database, check it out creating a database using CREATE DATABASE statement tutorial.
CREATE DATABASE mydb
Second, we can connect to this database to confirm if it is created successfully.
Third, we can use SQL DROP DATABASE to remove the mydb database.
DROP DATABASE mydb
Notes on SQL DROP DATABASE statement
There are some important points you should keep them in mind before using SQL DROP DATABASE statement.
- You should execute DROP DATABASE statement with extra cautious because when database is removed, it cannot be undone.
- To execute the DROP DATABASE you must have remove database privilege. Typically the database owner can remove database.
- Before removing database, make sure that you communicate with stakeholders and shutdown connections that are connecting to the database.
For more information on removing databases in specific database management systems:
- MySQL – delete database in MySQL
- Microsoft SQL Server – remove database in Microsoft SQL Server
- Oracle – remove Oracle database
- PostgreSQL – delete PostgreSQL database
In this tutorial, we have show you how to use the SQL DROP DATABASE statement to remove databases inside a database server.