IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Update a Key filed value from aother field


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
honey

New User


Joined: 15 Sep 2004
Posts: 5
Location: india

PostPosted: Thu Aug 23, 2007 9:37 am
Reply with quote

My tables are look like below. Table1 has 3 Key fields. I want to update the Key2 field values to Key1 (Both are Primary keys for the Table1) in Table1. This will affect the child table(s) Primary key field (Table2.Key1) too (Table2 has only 2 Key fields), because there is no Key field (Table1.Key2). How can I achieve this?

Parent table

Table1
Key1 Key2 Key3
A1 01 0001
A1 02 0002
A2 03 0003
A2 04 0004
A3 05 0005
A4 06 0006

Child Table

Table2
Key1 Key2
A1 0001
A1 0002
A2 0003
A2 0004
A3 0005
A4 0006
Back to top
View user's profile Send private message
ayyappareddy

New User


Joined: 17 Aug 2007
Posts: 5
Location: Trivandrum

PostPosted: Thu Aug 23, 2007 9:57 am
Reply with quote

Hi,

The question looks bit confused... Can you be bit clear...
Back to top
View user's profile Send private message
honey

New User


Joined: 15 Sep 2004
Posts: 5
Location: india

PostPosted: Thu Aug 23, 2007 11:04 am
Reply with quote

Resultant table should be like this

Table1
Key1 Key2 Key3
01 01 0001
02 02 0002
03 03 0003
04 04 0004
05 05 0005
06 06 0006

Child Table

Table2
Key1 Key2
01 0001
02 0002
03 0003
04 0004
05 0005
06 0006
Back to top
View user's profile Send private message
hariibm

New User


Joined: 05 Feb 2007
Posts: 61
Location: Chennai

PostPosted: Thu Aug 23, 2007 11:52 am
Reply with quote

Honey,

You can not alter the values of key1 if it is the primary key or part of the primary key.
Back to top
View user's profile Send private message
honey

New User


Joined: 15 Sep 2004
Posts: 5
Location: india

PostPosted: Thu Aug 23, 2007 12:58 pm
Reply with quote

Yes I know but i'd like to know how to unload the table, update the key filed and load it again.
Back to top
View user's profile Send private message
ayyappareddy

New User


Joined: 17 Aug 2007
Posts: 5
Location: Trivandrum

PostPosted: Thu Aug 23, 2007 2:02 pm
Reply with quote

Hi,

Practically speaking this would end in Referential integrity constraint. But, i could give a solution which might work or might not ( i am not sure).

In Table1 you can insert your require fields first,

Table1
Key1 Key2 Key3
A1 01 0001
A1 02 0002
A2 03 0003
01 01 0001
02 02 0002
03 03 0003


then alter the values in the child table


Table2
Key1 Key2
01 0001
02 0002
03 0003

Later delete the inserted values in table 1 and alter the existing values.
This is quite complicated one for huge data (costly).

This is just for Info.
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Thu Aug 23, 2007 2:29 pm
Reply with quote

Honey,

Quote:
Yes I know but i'd like to know how to unload the table, update the key filed and load it again.

Speak with your site DBA.

Ayyappa,

Quote:
Practically speaking this would end in Referential integrity constraint. But, i could give a solution which might work or might not ( i am not sure).

First you said something. Later contradicted in the very next sentence.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 631
Location: Wisconsin

PostPosted: Thu Aug 23, 2007 6:50 pm
Reply with quote

My opinion is this just a bad idea all around. If your really want to update key values you should be deleting the old rec and inserting a new rec. A mass change like that could kill your key pairs depending on the data.
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts To Unstring spaces in a field COBOL Programming 3
No new posts Can BPXBATCH update TAPE file COBOL Programming 3
No new posts Help required to reset decimal points... DFSORT/ICETOOL 10
No new posts Sorting Date Field DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
Search our Forums:


Back to Top