Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

Go Back  dBforums > Database Server Software > Oracle > Updating Parent Key Problem

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-03-08, 18:34
gunbilegt gunbilegt is offline
Registered User
 
Join Date: Mar 2008
Posts: 10
Updating Parent Key Problem

EMPLOYEES(ENO,ENAME,ZIP,HDATE)
PARTS(PNO,PNAME,QOH,PRICE,LEVEL)
CUSTOMERS(CNO,CNAME,STREET,ZIP,PHONE)
ODETAILS(ONO,PNO,QTY)
ZIPCODES(ZIP,CITY)


I tried to to update zipcodes.zip but got following error

ORA-02292: integrity constraint (SYSTEM.SYS_C003997) violated - child record
found
ORA-06512: at "SYSTEM.UPDATEZIP", line 6
ORA-06512: at line 1



Following is the block i'm using:


CREATE OR REPLACE PROCEDURE UPDATEZIP(OLDZIP IN NUMBER,
NEWZIP IN NUMBER)
IS
BEGIN

UPDATE ZIPCODES
SET ZIP = NEWZIP
WHERE ZIP = OLDZIP;

END UPDATEZIP;
Reply With Quote
  #2 (permalink)  
Old 04-04-08, 02:41
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 2,716
Quote:
ORA-06512: at "SYSTEM.UPDATEZIP", line 6
Bad, BAD idea to use SYSTEM as a schema for your own pleasure. If you continue to do that, I bet you'll regret it some day.

As of a problem you have, it is quite obvious: you can't modify 'zipcodes.zip' to a new value as long as there are child records which rely on "old" values. If it was allowed, there would be a mess once you decide to write a qurey which should return records based on join with the 'zipcodes' table.

Based on what you've written, 'zip' column appears in 'employees' and 'customers' tables. So, how to change 'zipcodes' table?

One way would be to create additional table which would contain pairs of old and new zip codes. Then INSERT new zip codes into the 'zipcodes' table, update 'employees' and 'customers' to point to newly added zip codes, and then (if you wish) remove "old" zip codes from the 'zipcodes' table.

Or, you might modify foreign key constraints to be deferrable; that way you could UPDATE 'zipcodes' table, then update 'employees' and 'customers' and - once it is done - COMMIT the changes.
Reply With Quote
Reply


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

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