Drop Table in PostgreSQL – Syntax, IF EXISTS, CASCADE, and Safety Tips | DbSchema
Table of Contents
- What DROP TABLE does
- Version notes
- DROP TABLE syntax in PostgreSQL
- Examples: drop one table, many tables, and schema-qualified tables
- CASCADE vs RESTRICT
- Safety checklist before dropping a table
- Drop tables visually in DbSchema
- FAQ
- Conclusion
DROP TABLE removes a table definition and all data stored in it. It is one of the most destructive PostgreSQL commands, so it is worth understanding the syntax, the dependency rules, and the safer review options before running it in production-like environments.
What DROP TABLE does
When you drop a table in PostgreSQL, you remove:
- the table itself
- all rows in the table
- indexes owned by that table
- triggers and rules defined on that table
- dependent foreign key constraints when you use
CASCADE
If you only want to remove data and keep the structure, use TRUNCATE instead. If you need to remove everything in a schema, see Drop All Tables in PostgreSQL.
Version notes
DROP TABLE,IF EXISTS,CASCADE, andRESTRICTare standard parts of modern PostgreSQL releases.- PostgreSQL DDL is transactional, so you can test a drop inside
BEGINandROLLBACKbefore committing. RESTRICTis the default behavior. PostgreSQL stops the command if dependent objects still exist.
DROP TABLE syntax in PostgreSQL
DROP TABLE [IF EXISTS] [schema_name.]table_name [, ...]
[CASCADE | RESTRICT];
Key parts of the syntax:
IF EXISTSprevents an error if the table is already gone- schema qualification such as
public.ordersavoids ambiguity CASCADEremoves dependent objects automaticallyRESTRICTrefuses the drop when dependencies exist
Examples: drop one table, many tables, and schema-qualified tables
Drop one table
DROP TABLE public.orders;
Drop a table only if it exists
DROP TABLE IF EXISTS public.orders;
Drop multiple tables in one statement
DROP TABLE IF EXISTS public.order_items, public.orders;
Drop a table with dependent objects
DROP TABLE public.orders CASCADE;
Use this carefully. CASCADE may remove views, foreign key constraints, or other objects that rely on the table.
Rehearse the drop inside a transaction
BEGIN;
DROP TABLE public.orders;
ROLLBACK;
This pattern is useful when you want to verify that the statement is valid before making the change permanent.
Before dropping anything, it often helps to list objects with Show Tables in PostgreSQL and inspect the table with Describe Table in PostgreSQL.
CASCADE vs RESTRICT
| Option | What it does | When to use it |
|---|---|---|
RESTRICT | Stops the drop if dependent objects exist | Safer default for production |
CASCADE | Removes dependent objects automatically | Faster for dev resets and controlled cleanups |
If you are not sure which objects depend on a table, review them first:
SELECT conname AS foreign_key_name,
conrelid::regclass AS referencing_table
FROM pg_constraint
WHERE contype = 'f'
AND confrelid = 'public.customers'::regclass;
This query is a good safety check before you drop a heavily referenced table.
Safety checklist before dropping a table
Before running DROP TABLE, ask:
- Am I connected to the correct database and schema?
- Do I need a backup or export first?
- Should I use
RESTRICTand review dependencies before allowingCASCADE? - Do I actually need
DROP TABLE, or wouldTRUNCATEbe enough? - Should this change be reviewed visually in DbSchema before it is executed?
If the goal is a larger cleanup, also see Create Table in PostgreSQL and Drop All Tables in PostgreSQL.
Drop tables visually in DbSchema
DbSchema gives you a visual way to inspect a PostgreSQL schema before you remove anything. Connect using the PostgreSQL JDBC driver, reverse-engineer the database, and check relationships directly in the diagram.
In DbSchema you can:
- select the table in the diagram or object tree
- review related foreign keys and dependent tables visually
- open the SQL Editor or generated SQL preview
- apply the change and refresh the model
This is especially useful when several teams share the same database and a table drop could affect reports, sync jobs, or integration tests. The connect to database and schema synchronization pages explain the workflow further.

FAQ
What is the difference between DROP TABLE, TRUNCATE, and DELETE?
DROP TABLE removes the table structure and data. TRUNCATE keeps the structure but removes all rows quickly. DELETE removes selected rows and can be filtered with WHERE.
How do I drop a table that is referenced by foreign keys?
Use CASCADE, or drop the dependent foreign key constraints first. Review the dependencies before executing the command.
Can I roll back DROP TABLE in PostgreSQL?
Yes, if the statement runs inside an explicit transaction and you have not committed yet.
How do I drop multiple tables at once?
List them in one DROP TABLE statement, separated by commas.
How do I remove all rows but keep the table?
Use TRUNCATE, not DROP TABLE.
Conclusion
To drop a table in PostgreSQL safely, start with the right syntax, check dependencies, and decide whether RESTRICT, CASCADE, or TRUNCATE best matches the job. IF EXISTS is a good habit for scripts, and transactions give you a safer rehearsal option before commit.
If you would rather inspect the schema visually first, DbSchema can show the table relationships, generate PostgreSQL SQL, and help you manage destructive changes through a JDBC connection with less guesswork.