In a Database Management System (DBMS), databases are created to store and manage data. However, sometimes a database is no longer needed. In such cases, the database can be permanently removed from the server using the DROP DATABASE command.
This command deletes the entire database along with all its tables, records, indexes, and other database objects.
The DROP DATABASE query is a Data Definition Language (DDL) command used to permanently delete an existing database from the database server.
Once a database is dropped, all data stored inside it is permanently lost and cannot be recovered unless a backup exists.
DROP DATABASE database_name;
When the DROP DATABASE command is executed:
DROP DATABASE student_db;
After executing this command, the student_db database and all its data will be completely removed from the server.
You can confirm the deletion by running:
SHOW DATABASES;
If the database has been deleted successfully, it will no longer appear in the list of databases.
IF EXISTSTo avoid errors when trying to delete a database that does not exist, MySQL provides the IF EXISTS clause.
DROP DATABASE IF EXISTS database_name;
DROP DATABASE IF EXISTS library_db;
If the library_db database does not exist, the system will not generate an error.
DROP DATABASE command permanently deletes the database.DROP DATABASE is a DDL command.IF EXISTS clause prevents errors if the database is not present.The DROP DATABASE command is used to remove a database completely from the DBMS server. It deletes all the tables and data associated with that database. Because this action is irreversible, it should be used carefully and usually only by database administrators.