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

how many of you tried this?


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: Thu Jun 17, 2004 11:55 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,
Code:

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.
[/img]
Back to top
View user's profile Send private message
rick

New User


Joined: 18 Jun 2004
Posts: 59
Location: Chennai

PostPosted: Fri Jun 18, 2004 3:56 pm
Reply with quote

Hi,

Primary key values can be changed. But the new value should no be already existing one.
Back to top
View user's profile Send private message
unna

New User


Joined: 15 Oct 2004
Posts: 17

PostPosted: Fri Oct 15, 2004 3:43 pm
Reply with quote

Hi ,
Primary key can be changed by using Alter Table command and not by Update .

Try with Alter table command and let me know. icon_smile.gif as i haven't tried on it.

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

Active User


Joined: 06 Dec 2004
Posts: 211
Location: Keane Inc., Minneapolis USA.

PostPosted: Thu Dec 09, 2004 2:49 pm
Reply with quote

Hi,

We can directly change primary key values using update. But it will give an error if a foreign key is created refering to this primary key. Ok U may got it.

Eg: EMP (EMPNO,ENAME,JOB,DETPTNO) DEPTNO is Foreign Key
DEPT(DEPTNO,DNAME,LOC) DEPTNO is primary key

In this situation if u try to change DEPTNO of DEPT u will get an error.


Bye,
Reddy
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

 


Search our Forums:

Back to Top