有一個表A,如果想知道這個表的主鍵被哪些表作為外鍵,則使用下面語句
select * from user_constraints t where t.r_constraint_name = 'PK_PM_PRD'
其中 'PK_PM_PRD' 是你這個表的主鍵的名稱
select
a.owner 外鍵擁有者,
a.table_name 外鍵表,
substr(c.column_name,1,127) 外鍵列,
b.owner 主鍵擁有者,
b.table_name 主鍵表,
substr(d.column_name,1,127) 主鍵列
from
user_constraints a,
user_constraints b,
user_cons_columns c,
user_cons_columns d
where
a.r_constraint_name=b.constraint_name
and a.constraint_type='R'
and b.constraint_type='P'
and a.r_owner=b.owner
and a.constraint_name=c.constraint_name
and b.constraint_name=d.constraint_name
and a.owner=c.owner
and a.table_name=c.table_name
and b.owner=d.owner
and b.table_name=d.table_name