Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 39491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:52:23+00:00 2026-05-10T14:52:23+00:00

I am trying to build a dependency graph of tables based on the foreign

  • 0

I am trying to build a dependency graph of tables based on the foreign keys between them. This graph needs to start with an arbitrary table name as its root. I could, given a table name look up the tables that reference it using the all_constraints view, then look up the tables that reference them, and so on, but this would be horrible inefficient. I wrote a recursive query that does this for all tables, but when I add:

START WITH Table_Name=:tablename 

It doesn’t return the entire tree.

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T14:52:24+00:00Added an answer on May 10, 2026 at 2:52 pm
        select parent, child, level from ( select parent_table.table_name parent, child_table.table_name child  from user_tables      parent_table,       user_constraints parent_constraint,       user_constraints child_constraint,       user_tables      child_table where parent_table.table_name = parent_constraint.table_name   and parent_constraint.constraint_type IN( 'P', 'U' )   and child_constraint.r_constraint_name = parent_constraint.constraint_name   and child_constraint.constraint_type   = 'R'   and child_table.table_name = child_constraint.table_name   and child_table.table_name != parent_table.table_name ) start with parent = 'DEPT' connect by prior child = parent 

    should work (replace the table name, of course) assuming that everything is in the same schema. Use the DBA_ versions of the data dictionary tables and conditions for the OWNER and R_OWNER columns if you need to handle cross-schema dependencies. On further reflection, this does not account for self-referential constraints (i.e. a constraint on the EMP table that the MGR column references the EMPNO column) either, so you’d have to modify the code to handle that case if you need to deal with self-referential constraints.

    For testing purposes, I added a few new tables to the SCOTT schema that also reference the DEPT table (including a grandchild dependency)

    SQL> create table dept_child2 (   2  deptno number references dept( deptno )   3  );  Table created.  SQL> create table dept_child3 (   2    dept_child3_no number primary key,   3    deptno number references dept( deptno )   4  );  Table created.  SQL> create table dept_grandchild (   2    dept_child3_no number references dept_child3( dept_child3_no )   3  );  Table created. 

    and verified that the query returned the expected output

    SQL> ed Wrote file afiedt.buf    1  select parent, child, level from (   2  select parent_table.table_name parent, child_table.table_name child   3   from user_tables      parent_table,   4        user_constraints parent_constraint,   5        user_constraints child_constraint,   6        user_tables      child_table   7  where parent_table.table_name = parent_constraint.table_name   8    and parent_constraint.constraint_type IN( 'P', 'U' )   9    and child_constraint.r_constraint_name = parent_constraint.constraint_name  10    and child_constraint.constraint_type   = 'R'  11    and child_table.table_name = child_constraint.table_name  12    and child_table.table_name != parent_table.table_name  13  )  14  start with parent = 'DEPT'  15* connect by prior child = parent SQL> /  PARENT                         CHILD                               LEVEL ------------------------------ ------------------------------ ---------- DEPT                           DEPT_CHILD3                             1 DEPT_CHILD3                    DEPT_GRANDCHILD                         2 DEPT                           DEPT_CHILD2                             1 DEPT                           EMP                                     1 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to build a GUI application in Java/Swing. I'm mainly used to painting GUIs
I trying to build and compile my xcodeproj in command line and it is
I'm trying to build a grammar with the following: NUMERIC: INTEGER | FLOAT |
I'm currently trying to build a personal website to create a presence on the
I am trying to build a function in C/C++ to sort an array and
I am trying to build an website for my college's magazine. I used the
I am trying to build out a useful 3d game engine out of the
I'm trying to build a better username/password field for my workplace and would like
I am trying to build an Eclipse application that would work with a linux/motif
I'm trying to build freetds but want it to include the static libraries in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.