MySQL DROP DATABASE Statement
MySQL DROP DATABASE Statement
The DROP DATABASE statement in MySQL is used to delete an existing database permanently along with all its tables, data, and objects.
⚠️ Warning: This action is irreversible. All data in the database will be lost.
🔹 Syntax
-
database_name→ Name of the database to delete.
🔹 Syntax with IF EXISTS
-
Prevents an error if the database does not exist.
🔹 Example 1: Delete a Database
-
Deletes the database named
SchoolDBpermanently.
🔹 Example 2: Delete Database If Exists
-
Only deletes
SchoolDBif it exists, otherwise no error occurs.
🔹 Key Points
-
DROP DATABASE deletes everything: tables, views, procedures, triggers, and data.
-
Always use IF EXISTS to avoid runtime errors.
-
Use with caution; consider backups before dropping a database.
-
After dropping, the database cannot be recovered unless you have a backup.
💡 Tip: Combine with SHOW DATABASES; to check existing databases before dropping:
