Skip to content

SQL DROP DATABASE Statement

DROP DATABASE deletes a database: every table in it, every row in those tables, and everything else the database holds.

DROP DATABASE database_name;

To remove a test copy of the accounts database:

DROP DATABASE ProductionAccountsTest;

Dropping a database that does not exist is an error. MySQL, PostgreSQL and SQL Server accept IF EXISTS, which skips the drop quietly instead, and is handy in setup scripts that may run more than once:

DROP DATABASE IF EXISTS ProductionAccountsTest;
  • Permissions: dropping a database usually needs administrator rights.
  • Open connections: most servers refuse to drop a database that someone is still connected to, including you. Connect to a different database before dropping this one.

To empty or remove a single table instead of the whole database, see DROP TABLE.