码迷,mamicode.com
首页 > 其他好文 > 详细

Day.1建表小作业

时间:2017-06-05 20:00:45      阅读:150      评论:0      收藏:0      [点我收藏+]

标签:innodb   htm   teacher   mysql   地址   art   one   作业   分享   

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建表小作业

标签:innodb   htm   teacher   mysql   地址   art   one   作业   分享   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!