If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back  dBforums > Database Server Software > Oracle > Parent key not found

LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Registered User
Join Date: Feb 2004
Posts: 1
Parent key not found

Hi all,

I have a problem with my SQL script.
I have 2 tables, a user table, and a user subscription table, with a foreign key from the user table. I created a simple script simply consisting of insert statements to insert some records into these 2 tables for testing purposes. I would insert the records to the user table first, then the corresponding records into the user subscription table. I only ran a commit at the end of the file.

The script ran fine when i ran it in Toad, yet when the DBA ran the script in production there was a "integrity constraint violated - parent key not found" for every user subscription record i tried to insert. Should i be doing a commit after inserting the user records before trying to insert the child records, or something?

Would really appreciate some advice on this, thanks a million!!

- SC -
Reply With Quote
  #2 (permalink)  
Registered User
Join Date: Feb 2004
Posts: 12
If I have understood correctly foreign key is created from user table to user subscription table. Then you should add entries to user subscription table first and then to user table.
Reply With Quote
  #3 (permalink)  
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Parent key not found

If you insert the parents first, then the children, and only commit at the end, that should work just fine. Or if the foreign key constraint is set to DEFERRED than it doesn't matter which you insert first.
Tony Andrews
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On