Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Foreign key problem

New Here ,
Oct 24, 2009 Oct 24, 2009

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

TOPICS
Server side applications

Views

373
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 24, 2009 Oct 24, 2009

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines