foreign key and primary key [message #48] |
Tue, 08 January 2002 03:58  |
diana365
Messages: 4 Registered: January 2002
|
Junior Member |
|
|
thanks for all the reply for my previous question.i've got the answear but there is still some confusion.i've create a table with 2 primary key with this statement:
>> create table product
( id number(5),
product_name char(5),
product_desc varchar(50),
primary key(id,product_name));
the table created successfully.but when i create another table>>item, with a column - id_product and define it as a foreign key with references to the table "product",it come out:
ORA-02270: no matching unique or primary key for this column-list...
why?
|
|
|
Re: foreign key and primary key [message #49 is a reply to message #48] |
Tue, 08 January 2002 04:10  |
Suresh Vemulapalli
Messages: 624 Registered: August 2000
|
Senior Member |
|
|
foreign key referenced column should be primary key or unique key. in your case, id column is not primary key/unique. you can define foreign key on composite column (id,product_name). otherwise define unique key constraint on id column of product table.
alter table product add constraint uq1 unique (id);
define foreign key now
alter table item add constraint fk1 foreign key (id_product) references product(id);
|
|
|