ORA-02298: cannot validate parent keys not found

L'errore si verifica perché si tenta di aggiungere una foreign key in una tabella che ha però righe orfane.
La tabella referenziata infatti non ha righe padri che fanno riferimento alle righe orfane della tabella figlio.

E s e m p i o
ORA-02298: cannot validate (hr.T223R_FK) - parent keys not found

 ALTER TABLE hr.tab223 ADD (
  CONSTRAINT T223R_FK
 FOREIGN KEY (tab223_ID_POST)
 REFERENCES hr.tab556 (ID_POST);


Per individuare le righe orfane eseguire la query seguente.

SQL>  select foreign_key from tabella_figlio
      where foreign_key not in ( select pk from tabella_padre);


E s e m p i o
select  tab223_ID_POST from  hr.T2444R_VRIC
where tab223_ID_POST not in (select ID_POST from hr.T2442R_POST);


Oppure

SQL> select foreign_key from tabella_figlio
     minus 
     select pk from tabella_padre;

Post popolari in questo blog

ORA-12154: TNS: il listener non è attualmente a conoscenza del servizio richiesto nel descrittore di connessione

Funzione TO_DATE

CREATE DATABASE LINK