[英]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.