DbSchema Database Designer

DbSchema | How to Drop All Tables from PostgreSQL



1.Drop all tables by deleting the schema

This example will drop all tables from the public schema.

DROP SCHEMA public CASCADE;
CREATE SCHEMA public;

If you want to drop tables from another schema, replace public with the name of your schema.

The first statement will drop the current schema and the next one will create a new schema with the same name but without any table.

After executing the two queries, you may also want to restore the grants for the new schema. Do this by executing:

GRANT ALL ON SCHEMA public TO postgres;
GRANT ALL ON SCHEMA public TO schema_name;

2.Drop all tables without deleting the schema

DO $$ DECLARE
    r RECORD;
BEGIN
    FOR r IN (SELECT tablename FROM pg_tables WHERE schemaname = current_schema()) LOOP
        EXECUTE 'DROP TABLE IF EXISTS ' || quote_ident(r.tablename) || ' CASCADE';
    END LOOP;
END $$;

3.Drop all tables from DbSchema

Using DbSchema you can drop all the tables from a PostgreSQL database simply by selecting all the tables from the left menu, right-clicking on them and select the ‘Drop’ option.

dbschema-drop

DbSchema is a visual diagram designer that allows you to edit & browse databases from an interactive diagram. Use powerful query tools to manage complex databases, export HTML5 documentation or work with the schema offline.

Download DbSchema for Free

DbSchema → Your Trusted Partner in Database Design

Simplify complex database workflows and improve productivity with DbSchema's advanced design and management tools

Visual Design & Modeling
Visual Design & Schema Layout

➤ Create and manage your database schema visually through a user-friendly graphical interface.

➤ Easily arrange tables, columns, and foreign keys to simplify complex database structures, ensuring clarity and accessibility.

GIT & Collaboration
Version Control & Collaboration

➤ Manage schema changes through version control with built-in Git integration, ensuring every update is tracked and backed up.

➤ Collaborate efficiently with your team to maintain data integrity and streamline your workflow for accurate, consistent results.

Data Explorer & Query Builder
Relational Data & Query Builder

➤ Seamlessly navigate and visually explore your database, inspecting tables and their relationships.

➤ Build complex SQL queries using an intuitive drag-and-drop interface, providing instant results for quick, actionable insights.

Interactive Documentation & Reporting
HTML5 Documentation & Reporting

➤ Generate HTML5 documentation that provides an interactive view of your database schema.

➤ Include comments for columns, use tags for better organization, and create visually reports.