MYSQL添加外键关联

SELECT * from stu st,course co,score sc 
where st.sid = sc.sid and sc.cid = co.cid

如果我们要给 sid 做一个约束,即两张表中的 sid 要一一对应,所以我们要添加外键

score 关联 stu:

此时,更改score 中 sid 的值,因为此处的sid 必须与 stu 中的sid对应,stu 中没有 sid= 1008,所以这个时候更改score中的sid = 1008 ,保存的时候会提示报错

posted @ 2018-08-01 15:23  郭东东郭  阅读(2317)  评论(0编辑  收藏  举报