Tuesday, May 12, 2015

ORA-02298 – parent keys not found

SQL> ALTER TABLE EMP_DET ADD CONSTRAINT EMP_DET_FK FOREIGN KEY ( NAME1 ) REFERENCES EMP( NAME1 );
ALTER TABLE EMP_DET ADD CONSTRAINT EMP_DET_FK FOREIGN KEY ( NAME1 ) REFERENCES EMP( NAME1 )
*
ERROR at line 1:
ORA-02298: cannot validate (HR.EMP_DET_FK) – parent keys not found

Cause :  This will show you the row (or rows) that exists in the child table that
don't exist in the parent table


Action  :  You have to either (added rows to the parent table which is already there in the child rows) or (removed the child rows that don't have parent table), then you can enable your Referential integrity constraints.

you can modify the below query as per your requirement and execute to know the missing rows.
 

SELECT NAME FROM SCHEMA.CHILD_TABLE A
WHERE NOT EXISTS (SELECT NAME FROM SCHEMA.PARENT_TABLE WHERE PRIMARY_KEY=A.KEY);

No comments:

Post a Comment

Thanks for giving comments!!