Question: I cannot get this working and this is the following error: Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint
I cannot get this working and this is the following error:
Error Code: 1217. Cannot delete or update a parent row: a foreign key constraint fails
drop table if exists Department; drop table if exists Employee; drop table if exists Dependent; drop table if exists Project; drop table if exists Proj_Work_Rel; drop table if exists Supplier; drop table if exists Part; drop table if exists Supp_Part_Rel; drop table if exists Supp_Part_Proj_Rel; drop table if exists Part_Structure_Rel;
create table Department ( Depid integer primary key, Depname varchar(10), Location varchar(10) ) ENGINE=InnoDB;
create table Employee ( `Emp#` integer primary key, `FirstName` varchar(10), `middleName` varchar(10), `LastName` varchar(10), `salary` integer, `Depid` integer, foreign key (Depid) references Department (Depid) ) ENGINE=InnoDB;
create table Dependent ( Did integer primary key, FirstName varchar(10), LastName varchar(10), `EMP#` integer, foreign key (`EMP#`) references Employee (`EMP#`) ) ENGINE=InnoDB;
create table Project ( Pid integer primary key, PName varchar(10), Location varchar(10), ProjManager integer, foreign key (ProjManager) references Employee (`EMP#`) ) ENGINE=InnoDB;
create table Proj_Work_Rel ( `EMP#` integer, ProjID integer, primary key (`EMP#` , ProjID), foreign key (`EMP#`) references Employee (`EMP#`), foreign key (ProjID) references Project (Pid) ) ENGINE=InnoDB;
create table Supplier ( `S#` integer primary key, Sname varchar(10), Status varchar(10), City varchar(10) ) ENGINE=InnoDB;
create table Part ( Partid integer primary key, PartName varchar(10), Price integer ) ENGINE=InnoDB;
create table Supp_Part_Rel ( `S#` integer, Partid integer, primary key (`S#` , Partid), foreign key (`S#`) references Supplier (`S#`), foreign key (Partid) references Part (Partid) ) ENGINE=InnoDB;
create table Supp_Part_Proj_Rel ( `S#` integer, Partid integer, Pid integer, Qty integer, primary key (`S#` , Partid , Pid), foreign key (`S#`) references Supplier (`S#`), foreign key (Partid) references Part (Partid), foreign key (Pid) references Project (Pid) ) ENGINE=InnoDB;
create table Part_Structure_Rel ( ExpPartID integer, IMPPartID integer, Qty integer, primary key (ExpPartID , ImpPartID), foreign key (ExpPartID) references Part (Partid), foreign key (IMPPartID) references Part (Partid) ) ENGINE=InnoDB;
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
