如何删除 PostgreSQL 数据库中的所有表? [英] How can I drop all the tables in a PostgreSQL database?
本文介绍了如何删除 PostgreSQL 数据库中的所有表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从命令行删除 PostgreSQL 中的所有表?
How can I drop all tables in PostgreSQL, working from the command line?
我不想删除数据库本身,只是删除所有表和其中的所有数据.
I don't want to drop the database itself, just all tables and all the data in them.
推荐答案
如果你所有的表都在一个单一的模式中,这个方法可以工作(下面的代码假设你的模式名称是 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;
这篇关于如何删除 PostgreSQL 数据库中的所有表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文