删除 PostgreSQL schema 中的所有表
执行以下查询以删除给定 schema 中的所有表。将 my-schema-name 替换为您的 schema 名称。在 Supabase 中,默认 schema 是 public。
这将删除所有表及其关联的数据。在继续之前,请确保您有最新的 备份。
1do $$ declare2 r record;3begin4 for r in (select tablename from pg_tables where schemaname = 'my-schema-name') loop5 execute 'drop table if exists ' || quote_ident(r.tablename) || ' cascade';6 end loop;7end $$;此查询通过列出给定 schema 中的所有表,然后为每个表执行 drop table 命令来工作(因此是 for... 循环)。
您可以使用 Supabase Dashboard 中的 SQL 编辑器,或者如果您正在 直接连接到数据库,则可以使用 psql 运行此查询。