首页 > 代码库 > Day.1建表小作业

Day.1建表小作业

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