Copy link to clipboard
Copied
I have to tables "student" and "grade". the grade table has the following columns: grade_ID, grade_Value, student_ID and course_ID. the "student_ID" column is a foreign key to the student table. when I try to insert a grade_Value with a student_ID that is not in the student table I get the following error: "Cannot add or update a child row: a foreign key constraint fails (`resultdb/grade`, CONSTRAINT `student_grade` FOREIGN KEY (`student_ID`) REFERENCES `student` (`student_ID`))". How can I validate that the student_ID entred has a corresponding entry in the student table so that I can generate an apprpriate warning for the user on the form
Copy link to clipboard
Copied
Use a stored procedure. The sproc cani first test if the key is valid. If it is, process and return sucess, otherwise return a failure message.