SQL Keywords

SQL DROP DB

What does SQL DROP DB do?

Permanently deletes an entire database, including all contained objects and data.
Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.

Compatible dialects for SQL DROP DB: PostgreSQL, MySQL, SQL Server, MariaDB, Snowflake, Redshift. Not supported in SQLite. Oracle supports DROP DATABASE only in multitenant container databases.

SQL DROP DB Full Explanation

DROP DB (usually written as DROP DATABASE) is a data definition language (DDL) command that removes a database catalog from the server. Once executed, every schema object inside the database—tables, views, procedures, functions, and data—is irretrievably erased. The command requires exclusive access to the target database and sufficient privileges (typically superuser or DROP privilege). Many systems offer an optional IF EXISTS clause to prevent errors when the database name is incorrect. Because the action is irreversible, it is common to wrap the statement in a transaction only if the underlying database engine supports transactional DDL; otherwise, a backup should be taken first.

SQL DROP DB Syntax

DROP DATABASE [IF EXISTS] database_name;

SQL DROP DB Parameters

  • IF EXISTS (optional keyword) - skips the error if database_name is not found
  • database_name (identifier) - name of the database to remove

Example Queries Using SQL DROP DB

-- Basic drop
DROP DATABASE sales_reporting;

-- Safe drop if the name might be absent
DROP DATABASE IF EXISTS staging_tmp;

Expected Output Using SQL DROP DB

  • The specified database catalog and every object it contains are deleted
  • The server returns a confirmation such as "DROP DATABASE" or number of affected objects
  • Subsequent attempts to connect to that database will fail

Use Cases with SQL DROP DB

  • Removing obsolete test or staging databases to free resources
  • Cleaning up temporary databases created during automated tests
  • Replacing a corrupted database after restoring from backup
  • Decommissioning a retired application’s data store

Common Mistakes with SQL DROP DB

  • Forgetting IF EXISTS and halting deployment scripts when the database is missing
  • Dropping the wrong environment (e.g., production instead of staging)
  • Assuming the command is transactional on systems where DDL auto-commits
  • Overlooking active connections that block the drop operation

Related Topics

CREATE DATABASE, ALTER DATABASE, DROP SCHEMA, DROP TABLE, BACKUP DATABASE

First Introduced In

SQL:1999

Frequently Asked Questions

Does DROP DB delete all tables automatically?

Yes. Every object inside the database catalog is removed with the command.

How do I avoid errors if the database may not be there?

Use IF EXISTS: `DROP DATABASE IF EXISTS db_name;` This safely skips the drop when the name is absent.

Can I roll back a DROP DB?

Only if your database engine supports transactional DDL and the command is run inside a transaction that has not been committed. For most systems, the action is permanent.

Why won't my DROP DB complete?

The target database still has active connections. Terminate or disconnect those sessions, then rerun the statement.

Sign up to get up to date news on SQL keywords
Welcome to the Galaxy, Guardian!
You'll be receiving a confirmation email

Follow us on twitter :)
Oops! Something went wrong while submitting the form.
Trusted by top engineers on high-velocity teams
Aryeo Logo
Assort Health
Curri
Rubie Logo
Bauhealth Logo
Truvideo Logo

Check out other commonly used SQL Keywords!