Integrity constraint - parent key not found

When I tried to enable constraint after disabling it, I got integrity constraint - parent key not found error.

Select owner, constraint_name, constraint_type, table_name, R_owner, R_constraint_name, status
from user_constraints where table_name = 'My_Table';

I got under R_constraint_name (called MySteps_PK) status is DISABLED. So, I did the following query for constraint named
MySteps_PK.

Select owner, constraint_name, constraint_type, table_name, R_owner, R_constraint_name, status
from user_constraints where table_name = 'MySteps' and I see all the constraints including MySteps_PK status are ENABLED.

How do I enable MySteps_PK in My_Table?
lium1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
Looks like you have a foreign key constraint and data violating it.

If I read this right you have rows in my_steps as a foreign key that aren't in my_table as the primary key?

I might have the tables backwards but it definitely a data issue.  MySteps_pk can be enabled but the foreign key to my_table cannot be enabled because of the data.

You can kind of see what you describe in the following test case:
drop table tab1 purge;
drop table tab2 purge;

create table tab1(col1 char(1), constraint tab1_pk primary key(col1));
create table tab2(col1, constraint tab2_fk foreign key (col1) references tab1(col1) INITIALLY DEFERRED DEFERRABLE);

insert into tab2 values('a');

alter table tab2 enable constraint tab2_fk;

Open in new window


I cannot enable the constraint because the 'a' isn't in tab1.
0
johnsoneSenior Oracle DBACommented:
What I would do is create an EXCEPTIONS table.  That can be done with the supplied script @?/rdbms/admin/utlexcpt

Then enable the constraint with EXCEPTIONS INTO EXCEPTIONS added to the end of the command.  The constraint will fail.  But, this time there will be records in the EXCEPTIONS table that will contain the ROWIDs of the records that violate the constraint.  These are the records that need to be added to the parent table.

The documentation -> http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_3001.htm#SQLRF01001 has an example of this exact case.  It is :
ALTER TABLE employees
   ENABLE VALIDATE CONSTRAINT emp_manager_fk
   EXCEPTIONS INTO exceptions;

Open in new window

You just need to put in the name of  your table and the name of the constraint.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lium1Author Commented:
No comment!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.