Query a Table's Foreign Key relationships

后端 未结 9 1873
旧时难觅i
旧时难觅i 2020-12-03 01:40

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.

9条回答
  •  情话喂你
    2020-12-03 02:00

    Here's how to take Mike's query one step further to get the column names from the constraint names:

    select * from user_cons_columns
    where constraint_name in (
      select 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=''));
    

提交回复
热议问题