且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

外键列表及其引用的表

更新时间:2022-12-23 15:12:52

在表ALL_CONSTRAINTS的列r_ownerr_constraint_name中描述了所引用的主键.这将为您提供所需的信息:

The referenced primary key is described in the columns r_owner and r_constraint_name of the table ALL_CONSTRAINTS. This will give you the info you want:

SELECT a.table_name, a.column_name, a.constraint_name, c.owner, 
       -- referenced pk
       c.r_owner, c_pk.table_name r_table_name, c_pk.constraint_name r_pk
  FROM all_cons_columns a
  JOIN all_constraints c ON a.owner = c.owner
                        AND a.constraint_name = c.constraint_name
  JOIN all_constraints c_pk ON c.r_owner = c_pk.owner
                           AND c.r_constraint_name = c_pk.constraint_name
 WHERE c.constraint_type = 'R'
   AND a.table_name = :TableName