Question
drop table if exists Dept_Emp; drop table if exists Supp_Part; drop table if exists Supp_Part_Proj; drop table if exists Part_Structure; drop table if exists Emp_Dep;
drop table if exists Dept_Emp;
drop table if exists Supp_Part;
drop table if exists Supp_Part_Proj;
drop table if exists Part_Structure;
drop table if exists Emp_Dep;
drop table if exists Proj_Work;
drop table if exists Employee;
drop table if exists Department;
drop table if exists Dependent;
drop table if exists Project;
drop table if exists Supplier;
drop table if exists Part;
CREATE TABLE `Supplier`(
`S#` INT NOT NULL ,
`Sname_ID` VARCHAR(45) NULL ,
FOREIGN KEY (Sname_id)
REFERENCES Sname(Sname_ID),
`Status` VARCHAR(45) NULL ,
`City` VARCHAR(45) NULL ,
PRIMARY KEY (`S#`))
ENGINE = InnoDB;
CREATE TABLE `Sname`(
`Sname_ID` VARCHAR(45) NULL ,
`first` VARCHAR(45) NULL ,
`middle` VARCHAR(45) NULL ,
`last` VARCHAR(45) NULL ,
PRIMARY KEY (`Sname_ID`))
ENGINE = InnoDB;
CREATE TABLE `Supp_Part_Proj`(
`QTY` INT NOT NULL ,
`S#` INT NOT NULL ,
`Part_ID` INT NOT NULL ,
`Project_ID` INT NOT NULL,
PRIMARY KEY(`S#`, `Part_ID`, `Project_ID`))
ENGINE = InnoDB;
CREATE TABLE `Supp_Part`(
`S#` INT NOT NULL ,
`Part_ID` INT NOT NULL ,
PRIMARY KEY (`S#`, `Part_ID`),
foreign key(`S`) references supp_part_proj,
foreign key(`Part_ID`) references Supp_Part_Proj)
ENGINE = InnoDB;
CREATE TABLE `Part_Structure`(
`QTY` INT NOT NULL ,
`Part_ID` INT NOT NULL ,
`Part_ID2` INT NOT NULL ,
PRIMARY KEY (`Part_ID`, `Part_ID2`))
ENGINE = InnoDB;
CREATE TABLE `Employee`(
`EMP#` INT NOT NULL ,
`First` VARCHAR(45) NULL ,
`Middle` VARCHAR(45) NULL ,
`Last` VARCHAR(45) NULL ,
`SALARY` INT NOT NULL ,
PRIMARY KEY (`EMP#`))
ENGINE = InnoDB;
CREATE TABLE `Proj_Work`(
`Project_ID` INT NOT NULL ,
`EMP#` INT NOT NULL ,
PRIMARY KEY (`EMP#`, `Project_ID`),
foreign key(`EMP#`) references Employee,
foreign key(`Project_ID`) references Project)
ENGINE = InnoDB;
CREATE TABLE `Proj_Manager`(
`Project_ID` INT NOT NULL unique,
`EMP#` INT NOT NULL,
PRIMARY KEY (`EMP#`, `Project_ID`),
foreign key(`EMP#`) references Employee,
foreign key(`Project_ID`) references Project)
ENGINE = InnoDB;
CREATE TABLE `Emp_Dep`(
`Dependent_ID` INT NOT NULL unique,
`EMP#` INT NOT NULL,
PRIMARY KEY (`EMP#`, `Dependent_ID`),
foreign key(`EMP#`) references Employee,
foreign key(`Dependent_ID`) references Dependent)
ENGINE = InnoDB;
CREATE TABLE `Dependent`(
`Dependent_ID` INT NOT NULL unique,
PRIMARY KEY (`Dependent_ID`))
ENGINE = InnoDB;
CREATE TABLE `Dept_Emp`(
`Dept_ID` INT NOT NULL unique,
`EMP#` INT NOT NULL,
PRIMARY KEY (`EMP#`, `Dept_ID`),
foreign key(`EMP#`) references Employee,
foreign key(`Dept_ID`) references Dept_ID)
ENGINE = InnoDB;
CREATE TABLE `Department`(
`Dept_ID` INT NOT NULL unique,
PRIMARY KEY (`Dept_ID`),
foreign key(`Dept_ID`) references Dept_ID)
ENGINE = InnoDB;
Why am I receiving a foreign constraint error when trying to compile these tables? Can somebody please fix this.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started