日期:2014-05-16  浏览次数:20478 次

Oracle 查询所有表的主外键约束
select a.table_name 外键表名,a.column_name 外键列名,b.table_name 主键表名,b.column_name 主键列名
from
(select a.constraint_name,b.table_name,b.column_name,a.r_constraint_name
from user_constraints a, user_cons_columns b
WHERE a.constraint_type='R'
and a.constraint_name=b.constraint_name
) a,
(select distinct a.r_constraint_name,b.table_name,b.column_name
from user_constraints a, user_cons_columns b
WHERE   a.constraint_type='R'
and
a.r_constraint_name=b.constraint_name)
b
where a.r_constraint_name=b.r_constraint_name
order by b.table_name