DROP TABLE Statement

SQL · Working with Tables

Theory

DROP TABLE removes a table completely: its rows, its column definitions, its indexes, constraints and triggers, and the permissions granted on it. After DROP TABLE old_employees, any query mentioning old_employees fails because the table no longer exists. DROP TABLE IF EXISTS avoids an error when the table might already be gone, which is useful in scripts that re-run.

Dropping is usually permanent; you need a backup to recover, although some platforms offer recovery features (for example Snowflake UNDROP or Oracle's recycle bin). If other tables reference it through foreign keys, the drop is blocked, or with CASCADE (where supported) the dependent constraints are removed too. Views built on the table become broken. If you only want to empty a table and keep its structure, use TRUNCATE or DELETE instead.

Why we use it

Old staging tables, test copies and retired features leave clutter that confuses people and uses storage. DROP TABLE removes the whole object cleanly when it is no longer needed.

When to use it

Use DROP TABLE when the table itself should disappear. To clear data but keep the table, use TRUNCATE (all rows) or DELETE (some rows). Check dependencies such as views and foreign keys before dropping.

How it works

  1. DROP TABLE old_employees
  2. Does the table exist? Yes: Check dependencies. No: Error (or do nothing with IF EXISTS).
  3. Do foreign keys reference it? Yes: Block the drop (or remove them with CASCADE). No: Continue.
  4. Remove rows, columns, indexes, constraints and triggers
  5. Table name is free; the object is gone

Syntax

DROP TABLE table_name;

Example

DROP TABLE old_employees;

Key points

SQL topics

Introduction to SQL

Querying Data

Sorting Rows

Limiting Rows

Filtering Rows

Joining Multiple Tables

Grouping Rows

SET Operators

Working with Tables

Modifying Data

Views & Triggers

Conditional Expressions

SQL Subqueries

Aggregate Functions

Window Functions

String Functions

Date Functions

Math Functions

Extra Concepts

T
Tech Town
Log InSign Up Free
Home SQL Python DSA Power BI Snowflake Databricks Spark Gen AI Practice Problems Contest Blog

Master SQL from Zero to Pro

All SQL topics in one place. Click any topic in the sidebar — content opens right here without leaving the page.

{{ sectionCount }}
Sections
{{ topicCount }}
Topics
Free
Forever
Hands-on practice Practice SQL Online Solve 150 SQL interview problems in a live editor with instant checking. Start practising →
Section {{ sec.num }}

{{ sec.label }}

SQL  /  {{ current.sectionLabel }}  /  {{ current.name }}

{{ current.name }}

Theory

{{ current.def }}

Why we use it

{{ rich.why }}

When to use it

{{ rich.when }}

Diagram

{{ rich.dg.caption }}

{{ tb.title }}
{{ c.v }}
{{ rich.dg.op }}
➜
{{ rich.dg.output.title }}
{{ c.v }}
{{ nd.label }}
{{ nd.sub }}
{{ nd.label }}
{{ nd.sub }}
{{ rich.dg.left.title }}
{{ it }}
{{ rich.dg.right.title }}
{{ it }}
Flowchart — how it works
{{ nd.text }}
{{ nd.text }}
◇ {{ nd.text }}
Yes → {{ nd.yes }}
No → {{ nd.no }}
Syntax
{{ current.syntax }}
Example
{{ current.example }}
▶ Try It Live — runs against a real sample database
{{ liveError }}
{{ col }}
{{ cell }}
Key Points — click to check off as you learn
  • {{ pt.mark }} {{ pt.text }}

Share this topic