WikiGalaxy

Personalize

PostgreSQL Drop Table

Understanding DROP TABLE:

The DROP TABLE statement is used to remove an existing table from the database. It deletes the table structure and its data permanently.


DROP TABLE table_name;
    

Example 1: Basic Drop Table

To remove a table named employees, use the following command:


DROP TABLE employees;
    

Example 2: Drop Table If Exists

Use IF EXISTS to avoid an error if the table does not exist:


DROP TABLE IF EXISTS employees;
    

Example 3: Drop Multiple Tables

You can drop multiple tables in a single command:


DROP TABLE IF EXISTS employees, departments;
    

Example 4: Cascade Option

Use CASCADE to drop tables with dependent objects:


DROP TABLE employees CASCADE;
    

Example 5: Restrict Option

Use RESTRICT to prevent dropping if there are dependencies:


DROP TABLE employees RESTRICT;
    

Advanced Usage of DROP TABLE

Example 6: Drop Table with Serial Column

Dropping a table with a serial column will also drop the sequence:


DROP TABLE orders CASCADE;
    

Example 7: Drop Temporary Table

Temporary tables can be dropped like regular tables:


DROP TABLE temp_data;
    

Example 8: Drop Table with Constraints

Constraints associated with the table will be removed:


DROP TABLE projects CASCADE;
    

Example 9: Drop Table with Views

Dropping a table will also drop any views dependent on it:


DROP TABLE sales CASCADE;
    

Example 10: Drop Table with Inherited Tables

When dropping a parent table, inherited child tables will also be affected:


DROP TABLE parent_table CASCADE;
    
logo of wikigalaxy

Newsletter

Subscribe to our newsletter for weekly updates and promotions.

Privacy Policy

 • 

Terms of Service

Copyright © WikiGalaxy 2025