Oracle
 sql >> Base de Dados >  >> RDS >> Oracle

Lista de chaves estrangeiras e as tabelas que elas referenciam no Oracle DB


A chave primária referenciada é descrita nas colunas r_owner e r_constraint_name da tabela ALL_CONSTRAINTS . Isso lhe dará as informações que você deseja:
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