Is there any way to get all tables that have foreign keys to another table in oracle with a query?
Here is a good article with an answer:
select owner,constraint_name,constraint_type,table_name,r_owner,r_constraint_name
from all_constraints
where constraint_type='R'
and r_constraint_name in (select constraint_name from all_constraints
where constraint_type in ('P','U') and table_name='TABLE_NAME');
Assuming that both the parent and child tables are in the same schema do the following:
select t1.table_name child_table, t1.constraint_name, t2.table_name parent_table
from user_constraints t1, user_constraints t2
where t1.r_constraint_name = t2.constraint_name
Note that r_constraint_name is populated only for FK (type 'R') constraints, so the self-join only returns info of interest
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With