Oracle queries the reference relationship of a table

Source: Internet
Author: User

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:

  1. SelectA. table_name, a. COLUMN_NAME, c. table_name, c. column_nameFrom
  2. User_cons_columns a, user_constraints B, user_cons_columns c
  3. WhereA. constraint_name = B. CONSTRAINT_NAME
  4. AndB. r_constraint_name = c. constraint_name
  5. And(C. table_name ='Emp' OrA. table_name ='Emp');

The result is as follows: the first two columns refer to the last two columns.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.