Purpose
This statement is used to delete a database.
Syntax
DROP DATABASE [IF EXISTS] database_name
Parameters
| Parameter | Description |
|---|---|
| IF EXISTS | Prevents errors when the database does not exist. |
| database_name | Specifies the name of the database to be deleted. |
Examples
Delete the
test2database.obclient> DROP DATABASE test2;Attempt to delete a non-existent database named
notest.obclient> DROP DATABASE notest;Expected return result:
ERROR 1008 (HY000): Can't drop database 'notest'; database doesn't existobclient> DROP DATABASE IF EXISTS notest;Expected return result:
Query OK, 0 rows affected, 1 warningobclient> SHOW WARNINGS;Expected return result:
+-------+------+------------------------------------------------------+ | Level | Code | Message | +-------+------+------------------------------------------------------+ | Note | 1008 | Can't drop database 'notest'; database doesn't exist | +-------+------+------------------------------------------------------+ 1 row in set
