Python全栈之路-MySQL(二)

MySQL实践

create table class (              
cid int not null auto_increment primary key,              
caption char(20) not null
)engine=innodb default charset=utf8;


create table student (              
sid int not null auto_increment primary key,              
sname char(20) not null,
gender char(1) not null,
class_id int not null,
constraint fk_student_class foreign key (class_id) references class(cid)
)engine=innodb default charset=utf8;

create table teacher (              
tid int not null auto_increment primary key,              
tname char(20) not null
)engine=innodb default charset=utf8;

create table course (              
cid int not null auto_increment primary key,              
cname char(20) not null,
teacher_id int not null,
constraint fk_course_teacher foreign key (teacher_id) references teacher(tid)
)engine=innodb default charset=utf8;

create table score (              
sid int not null auto_increment primary key,              
student_id int not null,
course_id int not null,
number int not null,
constraint fk_score_student foreign key (student_id) references student(sid),
constraint fk_score_course foreign key (course_id) references course(cid)
)engine=innodb default charset=utf8;




insert into class(caption) values('三年二班'),('一年三班'),('三年一班');

insert into student(sname,gender,class_id) values('钢蛋','女',1),('铁锤','铁锤',1),('山炮','男',2);


insert into teacher(tname) values('波多'),('苍空'),('饭岛');

insert into course(cname,teacher_id) values('生物',1),('体育',1),('物理',2);

insert into score(student_id,course_id,number) values(1,1,60),(1,2,59),(2,2,100);

posted on 2017-06-05 17:14  万越天  阅读(117)  评论(0编辑  收藏  举报