having two PK for a table [message #222592] |
Mon, 05 March 2007 10:01  |
miroconnect@yahoo.com
Messages: 202 Registered: April 2006
|
Senior Member |
|
|
Suppose I have two primary keys for a table
col1 -values(a,b,c,d,e) col2 -values(1,2,3,4,5)
I know PK are unique and not null.
If two columns are PK
how does oracle enforce restrictions ?
I assume this table will allow a row with a,5 but not a row with a,1 because a,1 combination already exsists.
Is my assumption correct ?
|
|
|
Re: having two PK for a table [message #222594 is a reply to message #222592] |
Mon, 05 March 2007 10:08   |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
A piece of heartfelt advice: Try things for yourself. You'll learn more and remember the results for longer, and these things are SOOOOOOooooo easy to test.
SQL> create table PK_test (col_1 number, col_2 number);
Table created.
SQL> alter table pk_test add constraint pk_Test_pk_1 primary key (col_1);
Table altered.
SQL> alter table pk_test add constraint pk_Test_pk_2 primary key (col_2);
alter table pk_test add constraint pk_Test_pk_2 primary key (col_2)
*
ERROR at line 1:
ORA-02260: table can have only one primary key
|
|
|
|
Re: having two PK for a table [message #222975 is a reply to message #222858] |
Wed, 07 March 2007 02:00  |
JRowbottom
Messages: 5933 Registered: June 2006 Location: Sunny North Yorkshire, ho...
|
Senior Member |
|
|
True - and you can point Foreign keys at the Unique key too.
That does raise the question of exactly what the difference is between that and a Primary Key.
|
|
|