How to generate a CREATE script for several tables in pgAdmin III?

好久不见. 提交于 2019-12-09 13:42:06

问题


In pgAdmin III you can:

  • right-click a table;
  • scripts;
  • CREATE script;
  • save the script from the SQL Editor.

If one has to do this for more than one table, is there a way to combine the scripts in one file (apart from manually copy-pasting them)? If this can be done via psql prompt or phppgadmin, that will be ok too.


回答1:


Here's a way using pgAdmin.

  • Right-click on your database (or schema).
  • Choose "backup"
  • Under "Format" choose "plain"
  • Under "Dump Options #1" choose "Only schema"
  • Under "Objects" choose the tables you want.

Then click "backup". The output should be a plain text file with the create table statements.

Here's the PgAdmin documentation on backup.




回答2:


"pg_dump" is also an option here. The -s flag for schema-only and -t to select specific tables. It's not psql or pgAdmin though. It's a utility available to the PostgreSQL user. Example:

sudo su - postgres
pg_dump -s database 


来源:https://stackoverflow.com/questions/28716760/how-to-generate-a-create-script-for-several-tables-in-pgadmin-iii

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!