Generate an E-R Diagram by reverse-engineering a database [closed] Generate an E-R Diagram by reverse-engineering a database [closed] database database

Generate an E-R Diagram by reverse-engineering a database [closed]


Dot is part of the graphviz package, which is a pretty damn cool/useful tool. Of course, you'll need something to generate the dot files for graphviz. I've used SchemaSpy once or twice in the past, and it works pretty well, provided you have the relationships defined in the database.


Microsoft Visio will easily do this.


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.

SELECT '"' || Source.TABLE_NAME || '" -> "'            || Destiny.TABLE_NAME || '";' AS For_GraphVizFROM dba_constraints SourceJOIN dba_constraints DestinyON 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_NAMEORDER 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.