database 通过对数据库进行逆向工程来生成 ER 图
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/185967/
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
Generate an E-R Diagram by reverse-engineering a database
提问by Camilo Díaz Repka
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost any database which has a JDBC driver that can detect foreign-key associations.
注意:最初这个问题是针对 PostgreSQL 提出的,但是,答案几乎适用于任何具有可以检测外键关联的 JDBC 驱动程序的数据库。
Querying PostgreSQL data dictionary for foreign-keys and relationship between tables is very straightforward, but how can I use that information to generate a graph of the relations between tables?
查询 PostgreSQL 数据字典的外键和表之间的关系非常简单,但我如何使用该信息来生成表之间的关系图?
Any recommendations about tools that can do this?
关于可以执行此操作的工具的任何建议?
EDIT:I know GraphVIZ/DOT canbe useful, however, I don't know have any idea regarding how to code an app that would generate the directed graph .DOT file.
编辑:我知道 GraphVIZ/DOT可能很有用,但是,我不知道如何编写将生成有向图 .DOT 文件的应用程序。
采纳答案by Paul Wicks
Dot is part of the graphvizpackage, which is a pretty damn cool/useful tool. Of course, you'll need something to generate the dot files for graphviz. I've used SchemaSpyonce or twice in the past, and it works pretty well, provided you have the relationships defined in the database.
Dot 是graphviz包的一部分,这是一个非常酷/有用的工具。当然,您需要一些东西来为 graphviz 生成点文件。过去我曾使用过SchemaSpy一两次,只要您在数据库中定义了关系,它就可以很好地工作。
回答by Andrew
Microsoft Visio will easily do this.
Microsoft Visio 可以轻松做到这一点。
回答by Joe Pineda
At least for Oracle I run this query or ask the DBA to run it and send me the results. Results can be copied directly to a text file to be interpreted by Graphviz's tools, resulting in a database diagram.
至少对于 Oracle,我运行此查询或要求 DBA 运行它并将结果发送给我。结果可以直接复制到文本文件中以供 Graphviz 的工具解释,从而生成数据库图表。
SELECT '"' || Source.TABLE_NAME || '" -> "'
|| Destiny.TABLE_NAME || '";' AS For_GraphViz
FROM dba_constraints Source
JOIN dba_constraints Destiny
ON Source.owner='my_db_owner' AND Destiny.owner='my_db_owner'
AND Source.CONSTRAINT_TYPE='R'
-- theoretically this validation should be redundant
-- AND Destiny.Constraint_type = 'P'
AND Source.R_CONSTRAINT_NAME = Destiny.CONSTRAINT_NAME
ORDER BY Source.TABLE_NAME, Source.CONSTRAINT_TYPE, Source.CONSTRAINT_NAME
, Source.R_CONSTRAINT_NAME, Source.INDEX_NAME;
A similar query can be created easily for SQL Server, don't know about MySQL, PostgreSQL et al.
SQL Server 可以轻松创建类似的查询,不知道 MySQL、PostgreSQL 等。
回答by Zeemee
DBVisualizeris also a free and nice alternative.
DBVisualizer也是一个免费且不错的选择。