Parent Child relation:
to fetch parent/child tablename/columnname using table user_constraints and user_cons_columns
select cc.column_name as column_name, c.table_name as table_name, rc.column_name as pcolumn_name, r.table_name as ptable_name
from user_constraints c,
user_constraints r,
user_cons_columns cc,
user_cons_columns rc
where c.constraint_type = 'R'
and c.constraint_name = cc.constraint_name
and r.constraint_name = rc.constraint_name
and c.r_constraint_name = r.constraint_name
and cc.position = rc.position
and c.table_name = 'child_table_name';
to fetch parent/child tablename/columnname using table user_constraints and user_cons_columns
select cc.column_name as column_name, c.table_name as table_name, rc.column_name as pcolumn_name, r.table_name as ptable_name
from user_constraints c,
user_constraints r,
user_cons_columns cc,
user_cons_columns rc
where c.constraint_type = 'R'
and c.constraint_name = cc.constraint_name
and r.constraint_name = rc.constraint_name
and c.r_constraint_name = r.constraint_name
and cc.position = rc.position
and c.table_name = 'child_table_name';
No comments:
Post a Comment