Monday, February 2, 2009

Import error ORA-39083, ORA-02298 parent keys not found

Error Description
From live server I have taken a dump and then in another database I have imported it. All tables, indexes, functions, constraints, procedures went fine. But while importing REF_CONSTRAINT two constraints failed to create.
From the import log,
Processing object type SCHEMA_EXPORT/TABLE/CONSTRAINT/REF_CONSTRAINT
ORA-39083: Object type REF_CONSTRAINT failed to create with error:
ORA-02298: cannot validate (MAXIM.HIS_DET_HISID_FK) - parent keys not found
Failing sql is:
ALTER TABLE "MAXIM"."HISTORY_DETAIL" ADD CONSTRAINT "HIS_DET_HISID_FK" FOREIGN KEY
("HISTORY_ID") REFERENCES "MAXIM"."HISTORY" ("ID") ENABLE
ORA-39083: Object type REF_CONSTRAINT failed to create with error:
ORA-02298: cannot validate (MAXIM.FK_REGIS_PHON_SUBSCRIBERS) - parent keys not found
Failing sql is:
ALTER TABLE "MAXIM"."PHONES" ADD CONSTRAINT "FK_REGIS_PHON_SUBSCRIBERS"
FOREIGN KEY ("SB_ID") REFERENCES "MAXIM"."SUBSCRIBERS" ("ID") ENABLE


Cause of the Problem
ORA-02298 throws because it was trying to enable a foreign key constraint on a table with data populated into it but it does not find any references parent key. As to enable a constraint it must satisfy the constraint condition and it could not enable foreign key constraint, so above error arises.

There may be several scenarios behind ORA-02298 while you doing import operation.

1)The data being imported is from a database where there is more than one user. The export is being done in user/schema mode, so only that user's data is being exported. Any tables that the user does not own, but may have a referential integrity link to, are not exported.

2)The export is taken while database was in read write mode and export was taken consistent. That is if you take export with exp command then you did not use CONSISTENT=Y option. And if you take data pump export with expdp command then you did not use FLASHBACK_SCN or FLASHBACK_TIME parameter to make the dump consistent. As a result at first parent table is exported and then some data is inserted into parent as well as child table. After parent table is exported child table is exported and child table contains those rows which references are not exist inside the parent table existed in the dump file. So, in case of import while enabling constraint it could not enable because referenced parent key is not there.

Solution of the Problem
If you face problem for cause 1) then find the parent table and before exporting child tables first import the parent tables dump and then import user dumps. Although if you take full export it will solve the problem.

If you face problem for cause 2) then while taking export by using exp utility use CONSISTENT=Y option.
And if you take data pump export by using expdp utility then use FLASHBACK_SCN or FLASHBACK_TIME parameter. You can query from database for the values of these parameters and use those value. You can follow http://arjudba.blogspot.com/2008/05/export-data-to-previous-time-or-point.html in order to have an idea about usage of these parameters. To know more about FLASHBACK_SCN or FLASHBACK_TIME parameters search within this blog.

Related Documents
http://arjudba.blogspot.com/2008/05/how-to-get-scn-from-database-timestamp.html
http://arjudba.blogspot.com/2008/05/export-data-to-previous-time-or-point.html

No comments:

Post a Comment