Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: Making an ERD from an existing db
In article <robertdg-2910981126310001_at_robertsd-mac.hpw.pri.bms.com>, Dan
Roberts <robertdg_at_bms.com> writes
>Hello All
>
>
>I have an existing Oracle rdbms for which I would like to draw up an ERD.
>How can I get PK and FK information from the DB in the process of
>determining the realtionships btw the tables as I do a desc on each
>table??
>
>Thanks!!.Dan
>
Here is the text of a useful SQL snippet that I found buried deep within
on of the Oracle support notes CDs that accompanied 7.3.4.
--------------cut-----------
-- This will generate all schema information for the current user
SET ECHO OFF
SET TERMOUT OFF
SET FEEDBACK OFF
SET TIMING OFF
SET PAUSE OFF
SET PAGESIZE 0
SET LINESIZE 255
SPOOL tmp.sql
SELECT 'SELECT RPAD('''||table_name||''',30),RPAD('''||
tablespace_name||''',24), ' || 'TO_CHAR(COUNT(*),''9,999,999,999'') FROM ' || table_name || ';'FROM user_tables
PROMPT
PROMPT
SELECT 'SCHEMA QUICK-LIST FOR USERID ' || user ||
' AS OF ' || TO_CHAR(SYSDATE, 'DD-MON-YYYY HH24:MI') FROM DUAL;
PROMPT ==================================================================
PROMPT
PROMPT
PROMPT Tables Overview
PROMPT ===============
PROMPT
PROMPT Table Tablespace Number of Rows PROMPT ------------------------------ ------------------------ --------------|
PROMPT
PROMPT
PROMPT Referential Constraints
PROMPT ======================= PROMPT PROMPT Table Constraint T Referenced Constraint D PROMPT ------------------------ ------------------------ ---------------------------|
RPAD(constraint_name, 24) "Constraint", constraint_type "T", RPAD(r_constraint_name, 24) "Referenced Constraint", RPAD(delete_rule, 1) "D"
PROMPT
PROMPT
PROMPT Tables and Columns
PROMPT ================== PROMPT PROMPT Table Column T Len Pre ScaN
PROMPT ------------------------ ------------------------ - ---- --- ----|
RPAD(column_name, 24) "Column", DECODE(data_type, 'CHAR', 'C', 'VARCHAR', 'V', 'VARCHAR2', 'V', 'NUMBER', 'N', 'DATE', 'D', '?') "T", TO_CHAR(data_length,'999') "Len", TO_CHAR(data_precision,'99') "Pr", TO_CHAR(data_scale,'99') "Sc", nullable "N"
PROMPT
PROMPT
PROMPT Non-Constraint Indexes
PROMPT ====================== PROMPT PROMPT Table Index U Column PROMPT ------------------------ ------------------------ - ------------------------|
RPAD(i.index_name, 24) "Index", RPAD(i.uniqueness,1) U, RPAD(c.column_name,24) "Column"FROM user_indexes i, user_ind_columns c WHERE i.table_name = c.table_name
SPOOL OFF --------------cut-----------
Not very pretty, but it contains all that you might need.
Dare I mention Designer 2000 and reverse engineering?
HTH
--
Tim Shute
Software Engineering Manager
NiSoft (UK) Limited
Unit 8, 31 Ballynahinch Road, Carryduff, BELFAST BT8 8EH
Tel: +44 (0) 1232 814121, Fax: +44 (0) 1232 813962
email: tshute_at_nisoft.co.uk
Internet: www.nisoft.co.uk
Received on Wed Nov 04 1998 - 08:07:03 CST