Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Find all Parent and Child tables of a table in one query

greenyMay 5 2016 — edited May 5 2016

Version : 11.2.0.4

Has anyone got a single query which will provide both parent and child tables of a particular table?

In the below example, Table B's parent table is Table A and child table is Table C. I am looking for a query which will list both parent and Child tables of TableB .

SQL> create table A (id number constraint A_PK Primary key, descr varchar2(10));

Table created.

SQL> create table B (B_id number constraint UQ_B Unique , A_id number, detail varchar2 (25));

Table created.

SQL> create table C ( C_ID number , someID number,  somecol varchar2(25));

Table created.

SQL> alter table B add constraint fk_b_a foreign key (A_id) references A (ID) on delete cascade;

Table altered.

SQL> alter table C add constraint fk_c_b foreign key (someID) references B (B_ID) on delete cascade;

Table altered.

This post has been answered by Chris Hunt on May 5 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2016
Added on May 5 2016
8 comments
30,274 views