Home » SQL & PL/SQL » SQL & PL/SQL » foreign key and primary key
foreign key and primary key [message #48] Tue, 08 January 2002 03:58 Go to next message
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 Go to previous message
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);
Previous Topic: Need Help
Next Topic: Question of foreign key
Goto Forum:
  


Current Time: Thu Aug 06 02:57:53 CDT 2020