Skip to Main Content
  • Questions
  • How to get a list of tables with child tables?

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Yodit.

Asked: September 18, 2025 - 8:53 pm UTC

Last updated: September 19, 2025 - 7:04 am UTC

Version: LiveSQL2

You Asked

Hello Tom,

I’ve been assigned a task where I need to check whether a table has any child tables, and if so, list them.

For example, if the table name is ABC, I should be able to list all its child tables. I’m working in SQL Developer.

My question is: is there a simple query I can use to get this result, or is there a standard procedure/template I should follow?

I’ve come across several different procedures, and I’m a bit confused about which one is best to use.

https://livesql.oracle.com/next/?compressed_code=H4sIAAAAAAAACp2TUW%252BCMBSF3038D%252BcNTQZ7n3EJQt3YlBrA7JGUWjciggF8MOHHL1AywGpi1sf2nO%252Be3HtrE2tlemQ8AgBr6%252FnUAw%252F5T5zswpJFiSjg%252BPK1Pj5ZESsAM5q3MGVHAcD00XM8dfL2MINnaVHmLE5L6TF97A9hd6t6uMGz5HxMlR

and Connor said...

Something like this should get you started. I did this in the HR sample schema

SQL> select parent, child, level from (
  2    select pt.table_name parent, ct.table_name child
  3     from user_tables      pt,
  4          user_constraints pc,
  5          user_constraints cc,
  6          user_tables      ct
  7    where pt.table_name = pc.table_name
  8      and pc.constraint_type IN( 'P', 'U' )
  9      and cc.r_constraint_name = pc.constraint_name
 10      and cc.constraint_type   = 'R'
 11      and ct.table_name = cc.table_name
 12      and ct.table_name != pt.table_name
 13  )
 14  start with parent = 'COUNTRIES'
 15  connect by nocycle prior child = parent;

PARENT                         CHILD                               LEVEL
------------------------------ ------------------------------ ----------
COUNTRIES                      LOCATIONS                               1
LOCATIONS                      DEPARTMENTS                             2
DEPARTMENTS                    EMPLOYEES                               3
EMPLOYEES                      JOB_HISTORY                             4
DEPARTMENTS                    JOB_HISTORY                             3


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library