![]()
create database SMSL;
use SMSL;
#班级表
create table class(
cid int primary key,
caption varchar(6)
)ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
#老师表:teacher
create table teacher(
tid int primary key,
tname varchar(8) not null
)ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
#学生表
create table student(
sid int primary key,
sname varchar(8) not null,
gender varchar(2) not null,
class_id int not null
)ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
#课程表 course
create table course(
cid int primary key,
cname varchar(8) not null,
teacher_id int not null,
foreign key(teacher_id) references teacher(tid)
)ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
成绩表
create table score(
sid int primary key,
student_id int not null,
scorse_id int not null,
number int not null,
foreign key(student_id) references student(sid),
foreign key(scorse_id) references course(cid)
)ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;
建库建表