创库
create database lianx1 DEFAULT character set utf8
表################################
int, 数据类型,表示整数
not null 表示不能为空
auto_increment 表示自增
PRIMARY key 表示主键
constraint 外键名 foreign key(要关联的列) references 被关联的表(被关联的列);
创建班级表
create table class(
cid int not null auto_increment PRIMARY key,
caption char(32));
创建学生表
create table student(
sid int not null auto_increment PRIMARY key,
sname char(32),
gender char(32),
class_id int not null,
constraint stu1 foreign key (class_id) references class(cid));
创建老师表
create table teacher(
tid int not null auto_increment PRIMARY KEY,
tname char(32));
创建课程表
create table course(
cid int not null auto_increment PRIMARY KEY,
cname char(32),
tearch_id int not null,
constraint cour1 foreign key(tearch_id) references teacher(tid));
创建成绩表
create table score(
sid int not null auto_increment PRIMARY KEY,
student_id int,
corse_id int,
number char(32),
constraint score1 foreign key (student_id) references student(sid),
constraint score2 foreign key (corse_id) references course(cid));