1030 作业

1.MySQL -u root -p
2.输入密码
3.show databases; #(查看库)
4.没有就创建
5.create database school charset utf8; #(创建学校库)
6.use school; #(进学校库)
7.show tables; #(查看表)
8.没有就创建
9.create table class(cid int unsigned auto_increment primary key,caption char(32) not null default '')charset utf8; #(创建班级表)
10.desc class; #(查看班级表结构)
11.insert into class (cid,caption) values (1,'三年二班'); #(在班级表里添加数据)
12.select * from class; #(查看班级表数据)
13.create table teacher(tid int unsigned auto_increment primary key,tname char(32) not null default '')charset utf8; #(创建老师表)
14.insert into teacher(tname) values ('瑞兹'),('悠米'),('菲欧娜'); #(老师表添加数据)
15.select * from teacher; #(查看老师表数据)
16.create table student(sid int unsigned auto_increment primary key,sname varchar(32) not null default '',gender varchar(32) not null default '',class_id int unsigned ,constraint fk_class_student foreign key (class_id) references class (cid))charset utf8; #(创建学生表,关联班级表)
17.insert into student (sname,gender,class_id) values ('盖伦','男',1),('赵信','男',2),('卡特琳娜','女',3); #(学生表添加数据)
18.create table course(cid int unsigned auto_increment primary key,cname varchar(32) not null default '',teacher_id int unsigned,constraint fk_teacher_course foreign key (teacher_id) references teacher (tid))charset utf8; #(创建课程表,关联老师表)
19.insert into course (cname,teacher_id) values ('魔法',1),('策略',2),('技巧',3); #(课程表添加数据)
20.create table score(
sid int unsigned auto_increment primary key,
student_id int not null default 1,
course_id int not null default 1,
number int unsigned auto_increment primary key,
constraint fk_student_score foreign key (student_id) references student(sid),
constraint fk_course_score foreign key (course_id) references course(cid)
)charset utf8;
20.create table score(sid int unsigned auto_increment primary key,student_id int not null default 1,course_id int not null default 1,number int unsigned auto_increment primary key,constraint fk_student_score foreign key (student_id) references student(sid),constraint fk_course_score foreign key (course_id) references course(cid))charset utf8; #(建不出来!!!!!)

猜你喜欢

转载自www.cnblogs.com/793564949liu/p/11768732.html