且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何删除 PostgreSQL 数据库中的所有表?

更新时间:2023-01-31 13:30:15

如果你所有的表都在一个单一的模式中,这个方法可以工作(下面的代码假设你的模式名称是 public)

If all of your tables are in a single schema, this approach could work (below code assumes that the name of your schema is public)

DROP SCHEMA public CASCADE;
CREATE SCHEMA public;

如果您使用的是 PostgreSQL 9.3 或更高版本,您可能还需要恢复默认授权.

If you are using PostgreSQL 9.3 or greater, you may also need to restore the default grants.

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