转,Oracle查询外键关联

select aaa.owner 外键库,
       aaa.table_name 外键表,
       substr(c.column_name, 1, 127) 外键列,
       bb.owner 主键库,
       bb.table_name 主键表,
       substr(d.column_name, 1, 127) 主键列
  from user_constraints  aaa,
       user_constraints  bb,
       user_cons_columns c,
       user_cons_columns d
 where aaa.r_constraint_name = bb.constraint_name
   and aaa.constraint_type = 'R'
   and bb.constraint_type = 'P'
   and aaa.r_owner = bb.owner
   and aaa.constraint_name = c.constraint_name
   and bb.constraint_name = d.constraint_name
   and aaa.owner = c.owner
   and aaa.table_name = c.table_name
   and bb.owner = d.owner
   and bb.table_name = d.table_name

你可能感兴趣的:(转,Oracle查询外键关联)