PostgreSQL

PostgreSQL DROP TABLE

Permanently remove an existing PostgreSQL table and all data stored in it.

The DROP TABLE statement

The DROP TABLE statement removes an existing table from the database. Unlike DELETE, which removes rows while keeping the table, DROP TABLE removes the table structure as well.

Warning: Dropping a table permanently removes all rows, columns, indexes, and constraints belonging to that table. Confirm the table name and create a backup before running this statement.

Drop the products table

To remove the existing products table, run:

DROP TABLE products;

Result

PostgreSQL reports:

DROP TABLE

This confirms that the table was removed successfully.

Display the table

If you try to query the removed table:

SELECT * FROM products;

PostgreSQL returns an error because the table no longer exists:

ERROR: relation "products" does not exist
LINE 1: SELECT * FROM products;

Avoid an error when the table is missing

DROP TABLE IF EXISTS products;

IF EXISTS allows the statement to complete without an error when the table has already been removed.

Further Reading

Continue learning with these related tutorials:

Continue learning