The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
---
title: 'Drop all tables in a Postgres schema'
description: 'Useful snippet for deleting all tables in a given schema'
footerHelpType: 'postgres'
---
This query drops all tables in a given schema.
Replace `my-schema-name` with the name of your schema. In Supabase, the default schema is `public`.
<Admonition type="caution">
This deletes all tables and their associated data. Ensure you have a recent [backup](/docs/guides/platform/backups) before proceeding.
</Admonition>
Run the following SQL using the [SQL Editor](/dashboard/project/_/sql) in the Supabase Dashboard or with `psql` over a direct connection. To connect with `psql`, see [Direct connection](/docs/guides/database/connecting-to-postgres#direct-connection).
```sql
do $$ declare
r record;
begin
for r in (select tablename from pg_tables where schemaname = 'my-schema-name') loop
execute 'drop table if exists ' || quote_ident(r.tablename) || ' cascade';
end loop;
end $$;
```
This query works by listing out all the tables in the given schema and then executing a `drop table` for each (hence the `for... loop`).