I am having issues with executing this in mysql and getting foreign key related error. Please assist with necessary correction ------------------------------------------start -------------------------------------------- Create schema video_world Create Table CITIZEN( Citizen_Memid int NOT NULL, Citizen_Name varchar(30), Citizen_Address varchar(100), primary key (Citizen_Memid) ); Create Table CD ( Cd_ID int NOT NULL, Cd_Title varchar(50), primary key (Cd_ID) ); Create Table borrowedrecords ( borrowedrecordid int NOT NULL, Citizen_Memid int NOT NULL, pending_dues decimal(5,2) borroweddate_time datetime, returndate_time datetime, foreign key (Citizen_Memid) references CITIZEN(Citizen_Memid), primary key (borrowedrecordid), ); Create Table CitizenKeyfob ( Citizen_Memid int NOT NULL, borrowedrecordid int NOT NULL, Cd_ID int NOT NULL, foreign key (Citizen_Memid) references (CITIZEN) foreign key (borrowedrecordid) references (borrowedrecords) foreign key (Cd_ID) references (Cd) ); INSERT INTO Citizen (Citizen_Memid, Citizen_Name, Citizen_Address) VALUES ('10001', 'Christian' , '345 North st') INSERT INTO Cd (Cd_ID, Cd_Title) VALUES ('93883838', 'Jumanji') INSERT INTO borrowedrecords (borrowedrecordid, Citizen_Memid, pending_dues, returndate_time) VALUES ('919333', '10001', '0', '2020-05-20 09:16:23') INSERT INTO CitizenKeyfob (Citizen_Memid, borrowedrecordid, Cd_ID) VALUES ('10001', '919333', '93883838')
I need help with figuring out why my sql statements are not working properly.
Here is the complete list of query i wrote. I am having issues with executing this in mysql and getting foreign key related error. Please assist with necessary correction
------------------------------------------start --------------------------------------------
Create schema video_world
Create Table CITIZEN(
Citizen_Memid int NOT NULL,
Citizen_Name varchar(30),
Citizen_Address varchar(100),
primary key (Citizen_Memid)
);
Create Table CD
(
Cd_ID int NOT NULL,
Cd_Title varchar(50),
primary key (Cd_ID)
);
Create Table borrowedrecords
(
borrowedrecordid int NOT NULL,
Citizen_Memid int NOT NULL,
pending_dues decimal(5,2)
borroweddate_time datetime,
returndate_time datetime,
foreign key (Citizen_Memid) references CITIZEN(Citizen_Memid),
primary key (borrowedrecordid),
);
Create Table CitizenKeyfob
(
Citizen_Memid int NOT NULL,
borrowedrecordid int NOT NULL,
Cd_ID int NOT NULL,
foreign key (Citizen_Memid) references (CITIZEN)
foreign key (borrowedrecordid) references (borrowedrecords)
foreign key (Cd_ID) references (Cd)
);
INSERT INTO Citizen (Citizen_Memid, Citizen_Name, Citizen_Address)
VALUES ('10001', 'Christian' , '345 North st')
INSERT INTO Cd (Cd_ID, Cd_Title)
VALUES ('93883838', 'Jumanji')
INSERT INTO borrowedrecords (borrowedrecordid, Citizen_Memid, pending_dues, returndate_time)
VALUES ('919333', '10001', '0', '2020-05-20 09:16:23')
INSERT INTO CitizenKeyfob (Citizen_Memid, borrowedrecordid, Cd_ID)
VALUES ('10001', '919333', '93883838')
--------------------------------------------------------end -----------------------------------------
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 1 images