Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Primary key and Foreign key on same column

450923Jan 10 2006 — edited Jan 11 2006
Hi, I am able to create below tables , primary and foreign keys as below.
But Is this valid design? Can I define a column (ckey2 in table "child") as
primary key and as well as foreign key?

CREATE TABLE parent (
col1 NUMBER,
col2 NUMBER
);

CREATE TABLE child (
ckey1 NUMBER,
ckey2 NUMBER,
ckey3 NUMBER
);

alter table parent add constraint parent_pk primary key( col1 );


alter table child add constraint child_pk primary key( ckey2 );
alter table child add constraint child_fk foreign key( ckey2 ) references parent( col1);


Thanks.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 8 2006
Added on Jan 10 2006
4 comments
2,507 views