解决方法:

这个错误是由于在插入数据时,插入的student_id在students表中不存在所导致的。

可以先检查一下students表中是否存在对应的student_id,如果不存在,需要先在students表中插入该学生的信息,然后再插入exam_results表中的数据。

正确的插入语句如下:

INSERT INTO students (student_id, student_name) VALUES (101, 'John'); INSERT INTO students (student_id, student_name) VALUES (102, 'Jane'); INSERT INTO students (student_id, student_name) VALUES (103, 'Tom'); INSERT INTO students (student_id, student_name) VALUES (104, 'Mary'); INSERT INTO students (student_id, student_name) VALUES (105, 'Peter'); INSERT INTO students (student_id, student_name) VALUES (106, 'Lucy');

INSERT INTO exam_results (student_id, course_id, score) VALUES (101, 1, 80); INSERT INTO exam_results (student_id, course_id, score) VALUES (102, 1, 90); INSERT INTO exam_results (student_id, course_id, score) VALUES (103, 2, 75); INSERT INTO exam_results (student_id, course_id, score) VALUES (104, 2, 85); INSERT INTO exam_results (student_id, course_id, score) VALUES (105, 3, 70); INSERT INTO exam_results (student_id, course_id, score) VALUES (106, 3, 80)

INSERT INTO exam_results student_id course_id score VALUES 101 1 80;INSERT INTO exam_results student_id course_id score VALUES 102 1 90;INSERT INTO exam_results student_id course_id score VALUES 103 2

原文地址: https://www.cveoy.top/t/topic/hgsx 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录