Query a Table's Foreign Key relationships

Mark Roddy picture Mark Roddy · Sep 17, 2008 · Viewed 59.8k times · Source

For a given table 'foo', I need a query to generate a set of tables that have foreign keys that point to foo. I'm using Oracle 10G.

Answer

Mike Monette picture Mike Monette · Sep 17, 2008

This should work (or something close):

select table_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='<your table here>');