Tuesday, August 4, 2009

Reverse Engineer DDL to an ERD

So you always wanted to get a graphical view of the hundreds of tables in Oracle. Given below is the outline of the steps.


Generate the DDL from Oracle using the metadata packages.

SQL>select 'select dbms_metadata.get_ddl(''TABLE'',',''''table_name''''') from dual;' from user_tables;

select dbms_metadata.get_ddl('TABLE','ACCOUNT') from dual;
select dbms_metadata.get_ddl('TABLE','CHANNEL_DIM') from dual;
select dbms_metadata.get_ddl('TABLE','CUSTOMER_DIM') from dual;
select dbms_metadata.get_ddl('TABLE','PRICE_FACT') from dual;


Spool,Execute,Spool,Execute and obtain the DDL into a file for example
tables.lst

Created a
Perl Program to parse this DDL file and create an output DOT file that will be used as input by the AT&T provided Graphviz utility. This utility can be downloaded from GraphViz

The layout of the DOT file generated is provided
here

Take this file DOT file and use the dot utility that you downloaded from GraphViz
From the DOS prompt run.

c:\type input.dot dot -Tpng > output.png

Features of the perl program:

Prints * next to col name to indicate a Mandatory field
Prints # next to col name to indicate a Primary Key
Run in verbose mode to include the column size in the output image
Change the color and font size