作业5月5号
# 班级表 cid caption # 学生表 sid sname gender class_id # 老师表 tid tname # 课程表 cid cname teacher_id # 成绩表 sid student_id course_id number ```mysql # 课程表被学生表 班级表 学生表 老师表关联 create table course( course_id int primary key auto_increment, course_name varchar(32) ); insert into course(course_name) values('english'),('math'); # 班级表是被学生表与课程表关联的 create table class( cid int primary key auto_increment, class_name varchar(18) not null ); insert into class(class_name) values('python'),('linux'),('java'); # 班级与课程关联表 create table class2course( rid int primary key auto_increment, class_id int, course_id int, foreign key(class_id) references class(cid) on update cascade on delete cascade, foreign key(course_id) references course(course_id) on update cascade on delete cascade ); insert into class2course(class_id,course_id) values(1,2),(2,1),(3,2),(1,1); # 成绩表关联学生表 create table score( score_id int primary key auto_increment, english_score int default 0, math_score int default 0 ); insert into score values(),(),(); # 学生表关联班级表 create table student( sid int primary key auto_increment, sname char(16), sage int default 18, class_id int, score_id int unique, foreign key(class_id) references class(cid) on update cascade on delete cascade, foreign key(score_id) references score(score_id) on update cascade on delete cascade ); insert into student(sname,class_id,score_id) values('tank',1,2),('egon',2,1),('jason',3,3); create table teacher( tid int primary key auto_increment, name char(16), course_id int, foreign key(course_id) references course(course_id) on update cascade on delete cascade ); insert into teacher(name,course_id) values('tank',1),('egon',1),('alex',2);