Using Oracle, is there any way I can execute a query to determine what relationship a specific table has with any other tables in my database? I'm fiddling with the all_constraints
table as of now.
views:
37answers:
2
+2
A:
Yes, you can do this for example:
select p.table_name, 'is parent of ' rel, c.table_name
from user_constraints p
join user_constraints c on c.r_constraint_name = p.constraint_name
and c.r_owner = p.owner
where p.table_name = 'MYTABLE'
union all
select c.table_name, 'is child of ' rel, p.table_name
from user_constraints p
join user_constraints c on c.r_constraint_name = p.constraint_name
and c.r_owner = p.owner
where c.table_name = 'MYTABLE'
Tony Andrews
2010-08-25 14:04:27
I'm able to query `all_constraints` but `user_constraints` returns nothing. Other than that, works like a charm. Thank you.
Mike
2010-08-25 15:19:36
+2
A:
I think your best bet is trying to extract as much information as you can from the foreign key constraints.
Have a look at this article at Database Journal that explains foreign key data mining in detail.
Amoeba
2010-08-25 14:06:13