Why this sql query showing me error.? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why this sql query showing me error.?

I have created two table and defined some attributes i have inserted data in course table when am inserting data in my students table it showing integrity constraints parent key not found what is the error am inserting same data in course_id which i have already inserted before CREATE TABLE course( course_id NUMBER, course_name VARCHAR2(255) NOT NULL, subject VARCHAR2(255) NOT NULL, PRIMARY KEY(course_id) ); CREATE TABLE student( s_id NUMBER, s_name VARCHAR2(255) NOT NULL, s_class VARCHAR2(255) NOT NULL, s_course NUMBER NOT NULL, s_address VARCHAR2(255) NOT NULL, PRIMARY KEY(s_id), FOREIGN KEY(s_course) REFERENCES course(course_id) );

15th Sep 2021, 1:57 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
6 Answers
+ 1
Brian right now i have fixed this issue i have deleted my student table when i again typed same inserting command it worked
15th Sep 2021, 6:32 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
Thanks for reply
15th Sep 2021, 6:32 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
The error would indicate that it could not find a match in course_id. Does the problem occur regardless of which course_id that you try? Could there be a nonprintable character in course_id or s_course, like a trailing space?
15th Sep 2021, 3:55 PM
Brian
Brian - avatar
0
It showing integrity constraints parent key not found while i am inserted same data in s_course which i have inserted in course_id
15th Sep 2021, 4:17 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
0
Is the INSERT statement field order misaligned with the values? Can you show us the exact INSERT statement here? If it is embedded SQL it helps to temporarily print the full query to the console so you can verify it.
15th Sep 2021, 4:36 PM
Brian
Brian - avatar
0
Good job! 👍 It would be fair to mark your own reply as the answer. Maybe you'll get the badge for it!
15th Sep 2021, 9:47 PM
Brian
Brian - avatar