Today, the developer asked me how to see which tables a table references or which tables are referenced by a table. It is best to display the tables in the form of charts (ergraphs, I started to want to open it through TOAD or other tools, but turned it into an image. Because the table is too large, I reported that the resources were insufficient, and then I wanted to use the data dictionary for a long time, to write the reference relationship:
Two data dictionaries are used: user_constraints and user_cons_columns.
The SQL statement is as follows. The table name "EMP" in two locations is converted to the table to be viewed at the same time, and the reference relationships related to the table "EMP" can be found:
- SelectA. table_name, a. COLUMN_NAME, c. table_name, c. column_nameFrom
- User_cons_columns a, user_constraints B, user_cons_columns c
- WhereA. constraint_name = B. CONSTRAINT_NAME
- AndB. r_constraint_name = c. constraint_name
- And(C. table_name ='Emp' OrA. table_name ='Emp');
The result is as follows: the first two columns refer to the last two columns.