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.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

SQL INSERT Error

SQL INSERT Error

Super Learner
0
Votes
1
Answer

INSERT INTO titles
(
emp_no,
title,
from_date
)
VALUES
(
999903,
‘Senior Engineer’,
‘1997-10-01’ );
I am getting the below error while I run this SQL query.
[caption id="attachment_120668" align="alignnone" width="300"] Please look at the Blue highlighted ERROR message.[/caption]

1 Answer

365 Team

Hi Archisman!
Thanks for reaching out.

We’ve answered this question here: https://365datascience.com/question/error-code-1452-cannot-add-or-update-a-child-row-a-foreign-key-constraint-fails-employees-titles-constraint-titles_ibfk_1-foreign-key-emp_no-references-employees-emp_no-on-delete-2/
But here’s the answer for your convenience.
Please stick to our general request to execute all code you see in the lectures and the exercises, in the given order. Doing this will prevent you from encountering some errors, such as this one – Error Code: 1452.
REASON FOR THE ERROR:
This error appears if you have already created another table, employees, where you have missed inserting data about the individual with id 999903. The relationship you have established between employees and dept_emp requires that you first insert a record in employees, and then insert a (related) record in dept_emp.
ON DELETE CASCADE means that if you remove record 999903 from employees, record 999903 will automatically be removed from dept_emp as well.
In brief, make sure the relationship between employees and dept_emp is valid and 999903 exists in employees so that you don’t get the same error the next time you try inserting 999903 in dept_emp.
SOLUTION: As explained in the article preceding this video, double-check if you’ve first inserted information about employee number 999903 in the employees table. Only then you should proceed with inserting information in the titles and dept_emp tables.
Hope this helps.
Best,
Martin

Thank you Martin! Yes I am able to do it now. I am really sorry for troubling you like that. I should’ve paid more attention. But I don’t know how this thing slipped away this time.

3 weeks

No worries at all, Archisman! I am glad you are able to proceed with the course now. Good luck and please feel free to post another question should you encounter any difficulties. Thank you. Best,Martin

2 weeks
×
Complete Data Science Training
Save 60%