View previous topic :: View next topic
|
Author |
Message |
meetsrk
New User
Joined: 13 Jun 2004 Posts: 85
|
|
|
|
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 |
|
|
rick
New User
Joined: 18 Jun 2004 Posts: 59 Location: Chennai
|
|
|
|
Hi,
Primary key values can be changed. But the new value should no be already existing one. |
|
Back to top |
|
|
unna
New User
Joined: 15 Oct 2004 Posts: 17
|
|
|
|
Hi ,
Primary key can be changed by using Alter Table command and not by Update .
Try with Alter table command and let me know. as i haven't tried on it.
Thanks, |
|
Back to top |
|
|
ovreddy
Active User
Joined: 06 Dec 2004 Posts: 211 Location: Keane Inc., Minneapolis USA.
|
|
|
|
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 |
|
|
|