如何删除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屋!
查看全文