add primary key problem [message #303671] |
Sat, 01 March 2008 21:45 |
salwa
Messages: 76 Registered: December 2007
|
Member |
|
|
Hi all
I do not Add primary key in existing table .how it possiable
say I have Existing Table
EMPNO NUMBER(4), primary key
ENAME VARCHAR2(10 BYTE),
JOB VARCHAR2(9 BYTE),
EMPSLNO VARCHAR2(10 BYTE)
Now Add another Primary key column(EMPSLNO)
my coding this
ALTER TABLE EMP_TEST ADD (
CONSTRAINT PK_EMP_TEST PRIMARY KEY (EMPSLNO))
but error message
Error on line 0
ALTER TABLE EMP_TEST ADD (
CONSTRAINT PK_EMP_TEST PRIMARY KEY (EMPSLNO))
ORA-02260: table can have only one primary key
PLse Help
|
|
|
|
Re: add primary key problem [message #303688 is a reply to message #303671] |
Sun, 02 March 2008 01:13 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
I believe you understand that it is Sunday today (and most of the people take a day off and probably do NOT visit this forum as usually). Be patient!
Quote: | ORA-02260: table can have only one primary key
| It is quite obvious, isn't it? Table already has a primary key and you can not have another one. So, either include a new column into it, or - if you don't want to do that - create a UNIQUE key/index instead. It will NOT act as if it was a primary key (for example, you will still be able to insert NULLs in there, so you'd have to do additional modification to a table).
However, the question is: what do you really want? Why do you think that 'empslno' should be a "primary key"? In a table like this one, 'empno' seems to be a good / logical choice for a primary key column. (What is 'empslno', anyway?)
[Updated on: Sun, 02 March 2008 01:17] Report message to a moderator
|
|
|
Re: add primary key problem [message #303803 is a reply to message #303688] |
Sun, 02 March 2008 22:41 |
salwa
Messages: 76 Registered: December 2007
|
Member |
|
|
my table column name
head_code primary key
item_code
item_name
i want
head_code-----item_code
01------------01
01------------02
02------------01
03------------01
how it possiable
pls help
|
|
|
Re: add primary key problem [message #303877 is a reply to message #303803] |
Mon, 03 March 2008 01:42 |
|
Littlefoot
Messages: 21823 Registered: June 2005 Location: Croatia, Europe
|
Senior Member Account Moderator |
|
|
I'm afraid I don't understand what you meant to say.
If 'head_code' is primary key, then you can NOT have data as presented in your last post (two 01 head_codes).
|
|
|