FOREIGN KEY
constraint with student_id
column and references it to students.id
ALTER TABLE notes
ADD CONSTRAINT fk_student_note
FOREIGN KEY (student_id)
REFERENCES students(id)
ON UPDATE CASCADE
ON DELETE RESTRICT
We can omit CONSTRAINT fk_student_note
sub-clause.
The difference is that if we omit the sub-clause, MySQL names the constraint automaticallyALTER TABLE notes
ADD FOREIGN KEY (student_id)
REFERENCES students(id)
ON UPDATE CASCADE
ON DELETE RESTRICT