SQL Tutorial SQL Advanced SQL Database SQL References

SQL - DROP DATABASE



The SQL DROP DATABASE statement is used to drop an existing SQL database.

Syntax

The syntax of using DROP DATABASE statement is given below:

DROP DATABASE DatabaseName;

Please note that to drop any database, appropriate privilege is required. Along with this, take extra measures while dropping a database. Deleting a database will result in loss of complete information stored in the database.

After dropping the database, in MySQL and MariaDB, the following command can be used to see the list of available databases.

SHOW DATABASES;

Similarly in SQL Server, the following statement can be used to see the list of available databases.

SELECT name FROM sys.databases;

Example: drop a database

To drop an existing database with name testDB, the following statement can be used:

DROP DATABASE testDB;

After dropping the database, the SHOW DATABASES; command can be used to see the list of databases available in MySQL & MariaDB:

SHOW DATABASES;
Result:
+-------------+
| Database    |
+-------------+
| SQLExample1 |
| SQLExample2 |
| SQLExample3 |
| SQLExample4 |
| SQLExample5 |
| SQLExample6 |
| SQLExample7 |
| SQLExample8 |
+-------------+
8 rows in set (0.00 sec)

Similarly in SQL Server, the following statement can be used to see the list of available databases.

SELECT name FROM sys.databases;
Result:

name        
--------------
SQLExample1 
SQLExample2 
SQLExample3 
SQLExample4 
SQLExample5 
SQLExample6 
SQLExample7 
SQLExample8