我一点一点地继续前进并理解 sql。下面我有4张桌子。我正在努力解决“多对多”和“一对多”的问题。早些时候在一个类似的问题上,我试图找出学院的课程,反之亦然。现在向我解释说,一张表用于课程,另一张表(academy_course)用于关系表,我可以在其中存储多对多关系。我是否需要对附属于学院的讲师应用相同的逻辑?每个学院都有一位独特的讲师。
CREATE TABLE academy
(
academy_id int(11) not null auto_increment,
name varchar(25) not null,
primary key (id),
);
CREATE TABLE course
(
course_id int(11) not null auto_increment,
course_name VARCHAR(50) NOT NULL ,
primary key (course_id),
);
CREATE TABLE academy_course
(
academy_id int(11) not null,
course_id int(11) not null ,
primary key (academy_id, course_id),
foreign key (academy_id) REFERENCES academy (academy_id) on delete cascade,
foreign key (course_id) REFERENCES course (course_id) on delete cascade
);
CREATE TABLE instructors
(
instructor_id VARCHAR(10) NOT NULL ,
academy_id INT NOT NULL ,
instructor_name VARCHAR(50) NOT NULL ,
primary key (instructor_id),
foreign key (academy_id) REFERENCES academy (academy_id) on delete cascade
);