Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Update a Key filed value from aother field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Update a Key filed value from aother field
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    Post subject: Reply to: Update a Key filed.........
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    Post subject: Reply to: Update a Key filed.........
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    Post subject: Reply to: Update a Key filed.........
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    Post subject:
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    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Thu Aug 23, 2007 2:29 pm    Post subject:
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: 632
Location: Wisconsin

PostPosted: Thu Aug 23, 2007 6:50 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> DB2 All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts INVALID FIELD OR CONSTANT IN SORTOF ?? Ron Klop DFSORT/ICETOOL 8 Wed Jan 11, 2017 3:44 pm
No new posts Performing arithmetic on input field zh_lad DFSORT/ICETOOL 31 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts -913/-911 Deadlock during UPDATE stat... NoSleep319 DB2 5 Fri Nov 18, 2016 12:37 am
No new posts How to update a portion of text in a ... Bill Woodger DFSORT/ICETOOL 25 Wed Nov 09, 2016 9:41 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us