Java bro

Java tutorial

Sql queries

Get children and descendants of a table

In this article we wre going to learn , How to find a children and it’s descendents of a table in Oracle . Here, we are going to find children and descendents of employee table .

Query :
SELECT LEVEL, CONS1.TABLE_NAME PARENT,
CONS2.TABLE_NAME CHILD
FROM USER_CONSTRAINTS CONS1, USER_CONSTRAINTS CONS2
WHERE CONS1.CONSTRAINT_TYPE IN (‘P’, ‘U’)
AND CONS2.R_CONSTRAINT_NAME = CONS1.CONSTRAINT_NAME
START WITH CONS1.TABLE_NAME LIKE UPPER(‘EMPLOYEE’)
CONNECT BY CONS1.TABLE_NAME = PRIOR CONS2.TABLE_NAME
ORDER BY LEVEL, CONS1.TABLE_NAME, CONS2.TABLE_NAME;

Comments are Closed

Theme by Anders Norén