🛠️ Scheduled Maintenance | We’ll be undergoing scheduled maintenance and upgrades between 00:00 PST Jan 26th until 00:00 PST Jan 28th. There may be brief interruption of services in that period. We apologize for the inconvenience.

The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Anybody can ask a question
Anybody can answer
The best answers are voted up and moderated by our team

SQL INSERT Statement

SQL INSERT Statement


I tried the insert statement exercise 1 but there was an error in the code which said: “Error code: 1452. Cannot add or update a child row: a foreign key constraint fails”. The code i typed in look exactly the same as the solution 1 given so I’m not sure whats the problem

1 Answer

Super Learner

Hello Hui,
in the table, where you are inserting the data, are there any FOREIGN key constrains? Check DDL section in “table_you_are_inserting_into” information window.  If yes, check for which columns and the corresponding referenced table.
If the value you are inserting is missing in the Referenced table, you will be unable to INSERT it in the corresponding column with FOREIGN key constraint.
Probably you are missing the value you are inserting in the Referenced table and maybe you just forgot to Insert it in the Referenced table first.
See if you have employee 999903 in your employees table. Since you are probably inserting emp_no 999903 in the titles table.
You can try it and reply if it helped or the problem prevails.
Best regards,
Maros J