SQL DROP Database
This tutorial will help us understand how to drop a database from the SQL Server with a few examples.
The DROP command removes all the objects stored in the database and database from the SQL server. The DROP query removes the database permanently from the SQL Server. If tables and views stored in the database are important for you, then the data backup needs to be kept in another database.
Following are the important key points to remember before deleting the database from the SQL Server:
1 The DROP query removes all the records or objects from the database and database from the Server. If data stored inside the database is usable in the future, we must keep the backup of objects stored inside the database, which we are deleting.
2 The most important key point is that we cannot remove the database from the SQL Server, which the database users use. While using the database, we try to remove the database, and then the output display is as follows:
Database Cannot be dropped.
The syntax of the DROP DATABASE query is as follows:
DROP DATABASE Database_Name;
We need to mention the database name in the SQL server, and we want to remove the remove permanently from the SQL Server. The database name needs to mention just after the DROP DATABASE keyword.
The below syntax is used to remove multiple databases from the SQL Server is as follows:
DROP DATABASE Database_Name_1, Database_Name_2, Database_Name_3, Database_Name_N;
Examples of DROP Database in SQL
We will execute the SHOW DATABASES command to check which databases are residing inside the SQL Server before removing the databases from the SQL Server.
SHOW DATABASES;
Database |
Cricket |
Demo |
Demodb |
Employee |
Ids |
information_schema |
Javatpoint |
Mumbai |
mysql |
performance_schema |
Phpadmin |
Registration |
Student |
student_1 |
Testdb |
WordPress |
World |

Example 1: Write a query to remove the cricket name database from the SQL Server.
DROP DATABASE Cricket;
In the above DROP DATABASE query example, we remove the cricket database name from the SQL Server.
We will execute the SHOW DATABASES query to check whether the cricket name database is successfully removed or not is as follows:
SHOW DATABASES;
Database |
Demo |
Demodb |
Employee |
Ids |
information_schema |
Javatpoint |
Mumbai |
mysql |
performance_schema |
Phpadmin |
Registration |
Student |
student_1 |
Testdb |
WordPress |
World |

As we can see, the cricket name database is successfully removed from the SQL Server.
Example 2: Write a query to remove the demo name database from the SQL Server.
DROP DATABASE Demo;
In the above DROP DATABASE query example, we remove the Demo name database from the SQL Server.
We will execute the SHOW DATABASES query to check whether the demo name database is successfully removed or not is as follows:
SHOW DATABASES;
Database |
Demodb |
Employee |
Ids |
information_schema |
Javatpoint |
Mumbai |
mysql |
performance_schema |
Phpadmin |
Registration |
Student |
student_1 |
Testdb |
WordPress |
World |

We dropped a database without adding arguments or parameters in the above examples.
1. IF EXISTS
IF EXISTS is one of the parameters, we can use it while removing the database in the SQL Server. Suppose there are several databases in the SQL Server, and we don't know whether the database is removing resides in the SQL Server. The purpose of the IF EXISTS parameter is to check whether the database we are going to drop is already removed or not in the SQL Server.
The syntax of the DROP DATABASE with the IF EXISTS parameter is as follows:
DROP DATABASE IF EXISTS DataBase_Name;
If the database exists, then the query will remove the database from the SQL Server, but if the database doesn't exist, the warning output is displayed.
Example 1: Write a query to remove the database with the IF EXISTS parameter.
DROP DATABASE IF EXISTS Demodb;
In the above DROP DATABASE query example, we dropped the database with the IF EXISTS parameter database name demodb. The query will remove the database if the database resides in the SQL Server. The warning output is displayed if the database is already removed from the SQL Server, and we try to execute the query.
We will execute the SHOW DATABASES query to check whether the demodb name database is successfully removed or not is as follows:
SHOW DATABASES;
Database |
Employee |
Ids |
information_schema |
Javatpoint |
Mumbai |
mysql |
performance_schema |
Phpadmin |
Registration |
Student |
student_1 |
Testdb |
WordPress |
World |

Example 2: Write a query to remove the database with the IF EXISTS parameter.
DROP DATABASE IF EXISTS Employee;
In the above DROP DATABASE query example, we dropped the database with the IF EXISTS parameter database name employee. The query will remove the database if the database resides in the SQL Server. The warning output is displayed if the database is already removed from the SQL Server, and we try to execute the query.
We will execute the SHOW DATABASES query to check whether the employee name database is successfully removed or not is as follows:
SHOW DATABASES;
Database |
Ids |
information_schema |
Javatpoint |
Mumbai |
mysql |
performance_schema |
Phpadmin |
Registration |
Student |
student_1 |
Testdb |
WordPress |
World |

Example 3: Write a query to remove the database with the IF EXISTS parameter.
DROP DATABASE IF EXISTS Employee;
In the above DROP DATABASE query example, we dropped the database with the IF EXISTS parameter database name employee. The query will remove the database if the database resides in the SQL Server. The warning output is displayed if the database is already removed from the SQL Server, and we try to execute the query.
The output of the above query is as follows:

As we can see in the output, 1 warning because the database name employee is already dropped from the server.