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
 

 

Can we change the value of primary key in DB2

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DB2
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    Post subject: Can we change the value of primary key in DB2
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    Post subject:
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    Post subject:
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    Post subject: primary key
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: 680
Location: NJ

PostPosted: Wed Oct 26, 2005 6:19 pm    Post subject: pkey change
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    Post subject:
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    Post subject:
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    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 How to change 'K' or 'M' use Sort vice_versa DFSORT/ICETOOL 5 Thu May 18, 2017 7:11 am
No new posts Fail to change physical VSAM filename... jacobdng CICS 7 Fri Jan 20, 2017 12:36 pm
No new posts Change date (DD/MM/YY) in 2nd record ... uday kiran DFSORT/ICETOOL 12 Wed Sep 07, 2016 10:57 pm
No new posts How to change dataset attributes of m... ignich7 JCL & VSAM 3 Thu Jul 21, 2016 9:17 pm
No new posts SFTP to primary and secondary servers mallik4u JCL & VSAM 4 Tue Jun 07, 2016 12:52 pm


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