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

关于数据库中如何查询主外键表和相关字段的SQL写法
select
a.owner as "用户名称",
c.table_name as "主键表",
d.column_name as "主键字段",
b.R_CONSTRAINT_NAME as "主键约束",
a.table_name as "外键表",
a.column_name as "外键字段",
a.constraint_name as "外加约束"
from user_cons_columns a,user_constraints b, user_constraints c, user_cons_columns d
where a.constraint_name = b.CONSTRAINT_NAME and  b.CONSTRAINT_TYPE = 'R'
and b.R_CONSTRAINT_NAME =  c.constraint_name
and c.constraint_type = 'P'
and c.constraint_name = d.constraint_name