注册 登录
编程论坛 MySQL论坛

怎么设置外键

编程2011 发布于 2011-10-30 13:21, 2382 次点击
怎么在navicat for mysql中设置外键、、、、
4 回复
#2
小文苑2011-11-20 11:25
回复 楼主 编程2011
创建外键约束
比如主表(Students)和两个子表(Courses,Scores)建立外键关系,关联字段有Stu_id,Cur_id
代码如下:
Alter table Scores
Add constrant Score_ibfk_1 Foreign Key(Cur_id)references Courses(Cur_id) on Delete Cascade;
Add constrant Score_ibfk_2 Foreign Key(Stu_id)references Courses(Stu_id) on Delete Cascade;
#3
lucky5635912011-12-10 08:55
看看视频就知道了
#4
lucky5635912011-12-16 09:32
foreign key
#5
lydiayang2012-03-23 17:12
两张表学生表student和成绩表score,student表的主键为stu_id,stu_id该字段也存在于score表中,那么在score表中可以创建外键约束
alter table  score add constraint fk_id  foreign key(stu_id) references student(stu_id);
1