外键关联:指利用外键将mysql中两个表关联起来。
1.创建study_record 表
注:key fk_student_key (stu_id) 表示与student表创建关联符 stu_id 存在问题
2.查看创建表记录:
3. 查看表结构
4. 添加表数据
注意 :在study_record表中添加数据时,stu_id只能选择在student中的id,否则会出错。 原因:study_record 数据依赖于student表。若插入student表中没有的数据则会破坏这种依赖关系。
4.删除数据
注:删除study_record 中数据可以,但是不能删除student表中数据。