create database student_info default character set utf8 collate utf8_general_ci;
#class 表
create table class_info(
cid int not null auto_increment primary key,
caption varchar(32)
)engine=innodb default charset=utf8;
create table student_info(
sid int not null auto_increment primary key,
sname varchar(32) not null,
gender ENUM("男","女"),
class_id int,
constraint student_class foreign key(class_id) references class_info(cid)
)engine=innodb default charset=utf8;
#老师 课程
create table teacher_info(
tid int not null auto_increment primary key,
tname varchar(32)
)engine=innodb default charset=utf8;
create table course_info(
cid int not null auto_increment primary key,
cname varchar(32) not null,
tearch_id int,
constraint course_teacher foreign key(tearch_id) references teacher_info(tid)
)engine=innodb default charset=utf8;
#成绩表
create table score_info(
sid int not null auto_increment primary key,
student_id int,
corse_id int,
number int,
unique(student_id,corse_id),
constraint score_student foreign key(student_id) references student_info(sid),
constraint score_course foreign key(corse_id) references course_info(cid)
)engine=innodb default charset=utf8;
insert into class_info(caption) values("三年二班");
insert into class_info(caption) values("三年三班");
insert into class_info(caption) values("五年一班");
insert into student_info(sname,gender,class_id) values("alex","男",1);
insert into student_info(sname,gender,class_id) values("egon","女",2);
insert into student_info(sname,gender,class_id) values("jim","女",2);
insert into teacher_info(tname) values("李老师");
insert into teacher_info(tname) values("王老师");
insert into teacher_info(tname) values("李鹏");
insert into teacher_info(tname) values("李三");
insert into teacher_info(tname) values("叶平");
insert into course_info(cname,tearch_id) values("生物",1);
insert into course_info(cname,tearch_id) values("物理",2);
insert into course_info(cname,tearch_id) values("体育",1);
insert into course_info(cname,tearch_id) values("化学",5);
insert into score_info(student_id,corse_id,number) values(6,3,100);
insert into score_info(student_id,corse_id,number) values(2,3,100);
insert into score_info(student_id,corse_id,number) values(2,1,100);
insert into score_info(student_id,corse_id,number) values(2,2,200);
insert into score_info(student_id,corse_id,number) values(2,3,200);
insert into score_info(student_id,corse_id,number) values(2,4,200);
insert into score_info(student_id,corse_id,number) values(6,4,200);
insert into score_info(student_id,corse_id,number) values(1,2,200);
insert into score_info(student_id,corse_id,number) values(1,4,200);
insert into score_info(student_id,corse_id,number) values(1,3,180);
insert into score_info(student_id,corse_id,number) values(1,1,170);
insert into score_info(student_id,corse_id,number) values(6,1,210);