mysql - SQL Foreign Key Constraint Error 1215 -
we trying make simple database facing same error , record did check other foreign key constraint questions didn't helped @ all.
as know when convert our eer diagram relations map, relations take primary keys of entities connected, in example: lets our entites have 1 primary key each of them tc_no, randevu_no, hasta_no , our relationt hat tied them going take primary keys of entities. like;
create table request( tc_no int not null, randevu_no int not null, hasta_no int not null, primary key(randevu_no,tc_no,hasta_no), foreign key(hasta_no) references patient(hasta_no) on delete cascade, foreign key(randevu_no) references appointment(randevu_no) on delete cascade, foreign key(tc_no) references patient(tc_no) on delete cascade );
however, getting same error. there no misspelling checked hours couldn't solved , have no idea why not working.
for people need code of database:
create table person( isim varchar(12) not null, soyisim varchar(12) not null, cinsiyet char(1) not null, dogum_tarihi date not null, adres varchar(150) not null, tc_no int not null, primary key(tc_no), unique key(tc_no)); create table employee( departman varchar(20) not null, sicil_no int not null, tc_no int not null, primary key(tc_no,sicil_no), unique key(sicil_no), foreign key(tc_no) references person(tc_no) on delete cascade ); create table patient( hastalik_gecmisi varchar(400) not null, kan_grubu char(4) not null, hasta_no int not null, tc_no int not null, primary key(tc_no,hasta_no), foreign key(tc_no) references person(tc_no) on delete cascade ); create table doctor( diploma_no int not null, brans varchar(40) not null, sicil_no int not null, tc_no int not null, primary key(tc_no,sicil_no,diploma_no), foreign key(tc_no) references employee(tc_no) on delete cascade, foreign key(sicil_no) references employee(sicil_no) on delete cascade ); create table appointment( hasta_no int not null, departman varchar(20) not null, randevu_no int not null, doktor_no int not null, tarih date not null, saat int not null, primary key(randevu_no) ); create table secretary( tc_no int not null, sicil_no int not null, primary key(sicil_no,tc_no), foreign key(sicil_no) references employee(sicil_no) on delete cascade, foreign key(tc_no) references employee(tc_no) on delete cascade ); create table request( tc_no int not null, randevu_no int not null, hasta_no int not null, primary key(randevu_no,tc_no,hasta_no), foreign key(hasta_no) references patient(hasta_no) on delete cascade, foreign key(randevu_no) references appointment(randevu_no) on delete cascade, foreign key(tc_no) references patient(tc_no) on delete cascade ); create table notify( randevu_no int not null, sicil_no int not null, primary key(randevu_no,sicil_no), foreign key(randevu_no) references appointment(randevu_no) on delete cascade, foreign key(sicil_no) references secretary(sicil_no) on delete cascade ); create table confirmation( hasta_no int not null, sicil_no_s int not null, diploma_no int not null, sicil_no_d int not null, primary key(sicil_no_s,hasta_no,diploma_no,sicil_no_d), foreign key(sicil_no_s) references secretary(sicil_no_s) on delete cascade, foreign key(hasta_no) references patient(hasta_no) on delete cascade, foreign key(diploma_no) references doctor(diploma_no) on delete cascade, foreign key(sicil_no_d) references doctor(sicil_no_d) on delete cascade );
does patient table have composite key primary key ? can show create statements of other tables too?
Comments
Post a Comment