MySQL DROP DATABASE Statement

MySQL DROP DATABASE Statement

The DROP DATABASE statement is used to delete an existing database in MySQL, along with all its objects such as tables, views, and stored procedures.


Syntax

DROP DATABASE databasename;
  • databasename: The name of the database you want to delete.

Important Notes:

  • Irreversible Action: Dropping a database is permanent and will completely remove all the data within that database, including tables, views, and other associated objects. This action cannot be undone.
  • Backup: Always ensure you have a backup of the database before performing this operation, especially in production environments.

Example

To drop a database named ShopDB, you would use the following SQL statement:

DROP DATABASE ShopDB;

This will delete the entire ShopDB database and all its contents.


IF EXISTS Option (Optional)

You can use the IF EXISTS clause to avoid errors if the database does not exist.

Syntax:

DROP DATABASE IF EXISTS databasename;

Example:

DROP DATABASE IF EXISTS ShopDB;

This ensures that the command does not raise an error if ShopDB doesn't exist.


Was this article helpful?