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 > DB2 > Updates on Keys within Transaction

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-11-10, 03:57
olel olel is offline
Registered User
 
Join Date: Oct 2009
Posts: 23
Updates on Keys within Transaction

Hello,

we have a database with around 30 tables which have a lot foreign key constraints. For some reason we have to change all the primary keys (and therefore the foreign keys obviously as well). Lets say we have to add 1000 to every key.

We wrote a script like this

Code:
UPDATE TABLE1 SET ID = ID + 1000, FK1 = FK1 + 1000, FK2 = FK2 + 1000
UPDATE TABLE2 SET ID = ID + 1000, FK1 = FK1 + 1000, FK2 = FK2 + 1000, FK3 = FK3 + 1000
UPDATE TABLE3 SET ID = ID + 1000, FK1 = FK1 + 1000, FK2 = FK2 + 1000
Unfortunately we are getting an SQL error with SQLSTATE 23504 "PARENT KEY IN A PARENT ROW CANNOT BE UPDATED BECAUSE IT HAS ONE OR MORE DEPENDENT ROWS IN RELATIONSHIP". I thought it should be possible to temporarly violate the foreign key constraints inside a transcation as long as they are ok at the end of the transaction, but apperently I'm wrong.

What do we have to do for being able to exceute the script.

Thanks in advance,
Ole
Reply With Quote
  #2 (permalink)  
Old 03-11-10, 08:26
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,229
alter table ... alter foreign key ... not enforced
Reply With Quote
  #3 (permalink)  
Old 03-12-10, 07:46
olel olel is offline
Registered User
 
Join Date: Oct 2009
Posts: 23
Thanks a lot!
Reply With Quote
Reply

Thread Tools
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