SQL Keywords

SQL DROP TABLE

What does SQL DROP TABLE do?

Permanently removes one or more tables and all their data from the database.
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 TABLE: Supported by PostgreSQL, MySQL, MariaDB, SQL Server, Oracle, SQLite, Snowflake, Redshift, BigQuery, and most other SQL-compliant systems.

SQL DROP TABLE Full Explanation

DROP TABLE is a Data Definition Language (DDL) command that deletes the specified table or list of tables from the schema, including all rows, indexes, constraints, and permission grants attached to those tables. Once executed, the operation is irreversible inside most databases unless it is issued inside a transaction that is later rolled back or the database supports a FLASHBACK-style feature. Some dialects offer safety switches such as IF EXISTS to avoid errors when the table is missing and CASCADE or RESTRICT to control how dependent objects (views, foreign keys, materialized views) are handled. Because it alters the catalog, DROP TABLE requires elevated privileges, typically the table owner or a database administrator.

SQL DROP TABLE Syntax

DROP TABLE [IF EXISTS] table_name [, ...]
[CASCADE | RESTRICT];

SQL DROP TABLE Parameters

  • IF EXISTS (keyword) - Optional flag that suppresses an error when the table does not exist.
  • table_name (identifier) - One or more table names to drop, separated by commas.
  • CASCADE (keyword) - Automatically drop objects that depend on the table (views, foreign keys, triggers).
  • RESTRICT (keyword) - Refuse to drop the table if any dependent objects exist (default in many systems).

Example Queries Using SQL DROP TABLE

-- Drop a single table
DROP TABLE employees;

-- Drop multiple staging tables only if they exist
DROP TABLE IF EXISTS temp_sales, temp_returns;

-- Drop a table and any objects that reference it (PostgreSQL)
DROP TABLE reports CASCADE;

Expected Output Using SQL DROP TABLE

  • Target tables disappear from the schema
  • Data, indexes, and privileges tied to those tables are lost
  • Queries against the dropped tables will raise an error such as "relation does not exist
  • " If CASCADE is used, dependent objects are also removed

Use Cases with SQL DROP TABLE

  • Cleaning up temporary or staging tables after batch processing
  • Removing obsolete tables during a schema migration
  • Regenerating test tables in automated test suites
  • Clearing mis-named or duplicate tables created by mistake

Common Mistakes with SQL DROP TABLE

  • Forgetting IF EXISTS and causing an error when the table is already gone
  • Using CASCADE without realizing it will delete dependent views and constraints
  • Confusing DROP TABLE with TRUNCATE TABLE (TRUNCATE keeps the table structure)
  • Attempting to drop a table inside a read-only transaction or without proper privileges

Related Topics

CREATE TABLE, ALTER TABLE, DROP VIEW, TRUNCATE TABLE, DROP DATABASE

First Introduced In

SQL-92

Frequently Asked Questions

Does DROP TABLE delete data permanently?

Yes. DROP TABLE removes the entire table definition and its data. The operation cannot be undone unless you roll back an open transaction or restore from backup.

Can I undo a DROP TABLE?

In most databases, no. After a DROP TABLE is committed, recovery requires a backup restore or special flashback features offered by some enterprise systems.

What is the difference between DROP TABLE and TRUNCATE TABLE?

DROP TABLE deletes the table structure and data. TRUNCATE TABLE quickly removes all rows but keeps the table definition, so you can still insert into it afterward.

How do I drop a table only if it exists?

Add the IF EXISTS clause: `DROP TABLE IF EXISTS table_name;` This prevents errors when the table is not present.

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!