Thursday, 15 August 2013

mysql - How to keep two table's data consistent when deleting records from one of them? -



mysql - How to keep two table's data consistent when deleting records from one of them? -

say, have 2 tables: students , course_scores .

the attributes in students student_id, name, sex;

while attributes in course_scores student_id, course, score.

when delete records students, corresponding records in course_scores should deleted, right? create them consistency.

could show me codes this?

alter table course_scores add together foreign key (student_id) references students (student_id) on delete cascade

the on delete cascade part want; delete rows in course_scores if corresponding student_id deleted. tables must utilize innodb engine.

mysql database database-design foreign-keys

No comments:

Post a Comment