PostgreSQL : Drop all tables in a schema - DevDummy

Latest

Views | Thoughts | Concepts | Techniques

Wednesday, October 04, 2017

PostgreSQL : Drop all tables in a schema

PostgreSQL : Drop all tables in a schema



  • Drop & Create The schema
DROP SCHEMA <schema_name> CASCADE;
CREATE SCHEMA <schema_name>;

  • Selectively Delete the tables
SELECT
    'drop table if exists "' || tablename || '" cascade;' as pg_drop
FROM
    pg_tables
WHERE
    schemaname= <schema_name>;

References

01. https://stackoverflow.com/questions/3327312/drop-all-tables-in-postgresql
02. https://skyvia.com/gallery/drop-all-tables-in-postgresql

No comments:

Post a Comment