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

Can we change the value of primary key in DB2


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

New User


Joined: 13 Jun 2004
Posts: 85

PostPosted: Sun Jun 13, 2004 11:50 am
Reply with quote

hi ppl,

can we change the value of primary key in DB2?

if not, then you are in for a suprise
if yes, then tell me why is that happening?

i.e in a table of emp,
consider, empno - integer, not null and primary key
ename - char(20)
esal - decimal(7,2)

i can write a sql statment like,

update emp set empno = empno + 1

the above statment did execute succesfully and incremented all the values of empno by 1.
pls try and tell me.
bye,
meetsrk
Back to top
View user's profile Send private message
priya

Moderator


Joined: 24 Jul 2003
Posts: 568
Location: Bangalore

PostPosted: Sun Jun 27, 2004 9:51 pm
Reply with quote

Yes, you can change the value of the primary key...
Back to top
View user's profile Send private message
muthukumar

New User


Joined: 24 Mar 2004
Posts: 29

PostPosted: Wed Aug 18, 2004 10:56 am
Reply with quote

Hi,

You can change the Primary key of the table but all the logs for that record will be lost if primary key is changed.

regards
Muthu
Back to top
View user's profile Send private message
gilli

New User


Joined: 28 Aug 2004
Posts: 5

PostPosted: Fri Sep 10, 2004 5:54 pm
Reply with quote

hi meetsrk,

there is nothing to get surprised.
you had just changed the value of primary key and not the primary key itself.
bye,
Back to top
View user's profile Send private message
khamarutheen

Active Member


Joined: 23 Aug 2005
Posts: 677
Location: NJ

PostPosted: Wed Oct 26, 2005 6:19 pm
Reply with quote

hi meetsrk,
its an easy thing to read the primary key and to add update with the existing and then again update the primary key. i don't think there is nothing to surp. the thing is if you are updating the same key value then it will show the error.
Back to top
View user's profile Send private message
krishnaiahc

New User


Joined: 31 Aug 2005
Posts: 21

PostPosted: Fri Oct 28, 2005 3:30 am
Reply with quote

All,

I have one question , if we modify the primary key in parent table "what about the foreign of the that primary key" ..

Thanks,
Krishna
Back to top
View user's profile Send private message
dewrid

New User


Joined: 28 Oct 2005
Posts: 4

PostPosted: Mon Oct 31, 2005 3:31 pm
Reply with quote

There are four options on a primary key update when there is a foreign key defined on it:
1. ON UPDATE RESTRICT
2. ON UPDATE NOACTION
3. ON UPDATE CASCADE
4. (DONT REMEMBER THE FOURTH ONE)

The first one wont allow you to update the key when there is a dependant key, the second also does the same9almost), while the third one modifies the dependant foreign key also with the new value of your parent key.
these options are declared when you are creating the child table.
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts 3270 personal communications. Can't c... TSO/ISPF 2
No new posts SELECT from data change table DB2 5
No new posts Trying to change copybook in online c... CICS 4
Search our Forums:

Back to Top