[英]SQL-linking two tables with a third table
我有两个表学生和课程。
我必须创建一个映射表来将这两个表与一组信息联系起来。 例如:来自 **Students ** 表的 Mary Murphy 将与她正在学习的网页设计课程的课程表相关联。
我怎样才能做到这一点?? 先感谢您。
您将使用第三个表, studentCourses
将是一个合理的名称。 它看起来像这样:
create table studentCourses (
studentCourseId int auto_increment primary key,
studentId int,
courseId int,
constraint fk_studentcourses_student foreign key (studentId) references students (studentId),
constraint fk_studentcourses_course foreign key (courseId) references students (courseId)
);
您可以包含其他信息,例如注册日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.