Skip to content

Instantly share code, notes, and snippets.

@craigs
Last active October 22, 2025 01:44
Show Gist options
  • Select an option

  • Save craigs/42ea907a068f5d3399ee7d9581a2e094 to your computer and use it in GitHub Desktop.

Select an option

Save craigs/42ea907a068f5d3399ee7d9581a2e094 to your computer and use it in GitHub Desktop.
Drop all tables in a Postgres database
-- This script will generate drop statements for
-- all tables in a Postgres database
select 'drop table if exists "' || tablename || '" cascade;' as "statement"
from pg_tables
where schemaname = 'public'
order by "statement";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment