postgresql 如何在 pgAdmin III 中为多个表生成 CREATE 脚本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28716760/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:55:21  来源:igfitidea点击:

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

postgresqlpsqlpgadminphppgadmin

提问by Alexander

In pgAdmin III you can:

在 pgAdmin III 中,您可以:

  • right-click a table;
  • scripts;
  • CREATE script;
  • save the script from the SQL Editor.
  • 右键单击一个表;
  • 脚本;
  • 创建脚本;
  • 从 SQL 编辑器保存脚本。

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.

如果必须对多个表执行此操作,是否有办法将脚本合并到一个文件中(除了手动复制粘贴它们)?如果这可以通过 psql 提示或 phppgadmin 完成,那也可以。

回答by mlinth

Here's a way using pgAdmin.

这是使用 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.
  • 右键单击您的数据库(或架构)。
  • 选择“备份”
  • 在“格式”下选择“普通”
  • 在“Dump Options #1”下选择“Only schema”
  • 在“对象”下选择您想要的表。

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

然后点击“备份”。输出应该是带有 create table 语句的纯文本文件。

Here'sthe PgAdmin documentation on backup.

这是有关备份的 PgAdmin 文档。

回答by OverworkedTechydude

"pg_dump"is also an option here. The -sflag for schema-only and -tto select specific tables. It's not psqlor pgAdminthough. It's a utility available to the PostgreSQL user. Example:

“pg_dump”也是这里的一个选项。-s仅模式和-t选择特定表的标志。它不是psqlpgAdmin虽然。它是 PostgreSQL 用户可用的实用程序。例子:

sudo su - postgres
pg_dump -s database