oracle10g - No matching unique or primary key for column-list in oracle -
create table student_details01 (usn varchar(20) not null, student_name varchar2(20) not null, branch varchar2(20) not null, contact_no number(10) not null, fathers_name varchar2(20) not null, home_address varchar(50) not null, dob date not null, local_address varchar2(50), email_id varchar2(20), doj date, hid number not null, primary key (usn,hid) ); create table mess( s_no number not null, hid number references student_details01(hid), no_of_breakfast int, no_of_meals int, amt_of_breakfast int, amt_of_meals int, total int not null, primary key(s_no) );
student_details01
table executed, mess table gives following error:
no matching unique or primary key column-list.
the ora-2270 : no matching unique or primary key column-list
error quite simple: happens when columns reference in foreign key not match primary key or unique constraint on parent table. common reasons are
- the parent lacks constraint altogether
- the parent table's constraint compound key , haven't referenced columns in foreign key statement.
to fix issue try below:
create table mess ( s_no number, s_hid number, s_uno varchar (20), --added column no_of_breakfast int, no_of_meals int, amt_of_breakfast int, amt_of_meals int, total int not null, constraint mess_pk primary key (s_no), constraint fk_id_dtls foreign key (s_hid, s_uno) references student_details01 (hid, usn) );
Comments
Post a Comment