DROP TABLE

Overview

The DROP TABLE statement permanently deletes a table and all its data, structure, indexes, triggers, constraints, and related objects.

Warning: DROP TABLE is irreversible and will permanently delete all data in the table. Use with extreme caution!

Basic Syntax

DROP TABLE Syntax
DROP TABLE table_name;

Examples

Example 1: Drop a Single Table

Delete a table
DROP TABLE Customers;

Example 2: Drop Multiple Tables

Delete multiple tables
DROP TABLE Customers, Orders, Products;

Example 3: Drop if Exists

Avoid error if table doesn't exist
-- MySQL
DROP TABLE IF EXISTS Customers;

-- SQL Server
IF OBJECT_ID('Customers', 'U') IS NOT NULL
DROP TABLE Customers;

-- PostgreSQL
DROP TABLE IF EXISTS Customers;

Example 4: Drop with CASCADE (PostgreSQL)

Drop table and dependent objects
-- PostgreSQL: Drop table and dependent objects
DROP TABLE Customers CASCADE;

Important Warnings

CRITICAL: DROP TABLE will:

Dropping Tables with Foreign Keys

When a table has foreign key relationships, you need to handle dependencies:

Drop tables with dependencies
-- Order matters: Drop dependent tables first
DROP TABLE IF EXISTS OrderItems;  -- Drop child table first
DROP TABLE IF EXISTS Orders;      -- Then parent table
DROP TABLE IF EXISTS Customers;   -- Finally this table

-- Or use CASCADE (PostgreSQL)
DROP TABLE Customers CASCADE;

Safety Checklist

Before dropping a table, verify:

Checking Dependencies

Before dropping a table, check for dependencies:

Check for foreign key dependencies
-- MySQL: Find foreign keys referencing a table
SELECT 
    TABLE_NAME,
    CONSTRAINT_NAME,
    REFERENCED_TABLE_NAME
FROM information_schema.KEY_COLUMN_USAGE
WHERE REFERENCED_TABLE_NAME = 'Customers';

-- SQL Server: Find dependencies
SELECT 
    OBJECT_NAME(parent_object_id) AS referencing_table,
    name AS constraint_name
FROM sys.foreign_keys
WHERE referenced_object_id = OBJECT_ID('Customers');

Alternative: TRUNCATE vs DROP

Understanding the difference:

Operation What It Does Table Structure
TRUNCATE Deletes all rows, keeps table structure Preserved
DROP Deletes table completely Removed
Use TRUNCATE to clear data without dropping
-- Keep table, remove all data
TRUNCATE TABLE Customers;

-- Completely remove table
DROP TABLE Customers;

Common Errors

Best Practices

When to Use DROP TABLE

When NOT to Use DROP TABLE

Next Steps

Learn about modifying tables with ALTER TABLE, or explore table constraints in Constraints.