首页 > 其他 > 详细

Day.1建表小作业

时间:2017-06-05 19:44:51      阅读:271      评论:0      收藏:0      [点我收藏+]

Mysql练习题博客地址:http://www.cnblogs.com/wupeiqi/articles/5729934.html

代码如下:

技术分享
create table class(
    cid int not null primary key
,caption char(10))engine=innodb default charset=utf8;

insert into class values(1,三年二班),(2,一年三班),(3,三年一班);
班级表class
技术分享
create table teacher(
    tid int not null primary key,tname char(10))engine=innodb default charset=utf8;

insert into teacher values(1,egon),(2,alex),(3,wusir);
教师表teacher
技术分享
create table student(
    sid int not null primary key,sname char(10),gender enum(,),class_id int not null,constraint fk_sc foreign key (class_id) references class(cid))engine=innodb default charset=utf8;

insert into student values(1,钢蛋,,1),(2,铁锤,,1),(3,山炮,,2);
学生表student
技术分享
create table course(
    cid int not null primary key,cname char(10),teacher_id int not null,constraint fk_ct foreign key (teacher_id) references teacher(tid))engine=innodb default charset=utf8;

insert into course values(1,生物,1),(2,体育,1),(3,物理,2);
课程表course
技术分享
create table score(
    sid int not null primary key,student_id int not null,course_id int not null,number int not null,constraint fk_ss foreign key (student_id) references student(sid),constraint fk_scadd foreign key (course_id) references course(cid))engine=innodb default charset=utf8;

insert into score values(1,1,1,60),(2,1,2,59),(3,2,2,100);
分数表score

 

Day.1建表小作业

原文:http://www.cnblogs.com/lxyoung/p/6946611.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!