MySQL数据库上机考核内容
1、正常登录 MySQL-Unicode 客户端(5 分);

2.创建数据库 sykh (5 分);
create database sykn;
use sykn; #进入数据库
3、打开本机 MySQL 中 My.ini 文件,修改客户端端口为 3309(5 分);
#找到mysql安装根目录下my.ini


4.在 sykh 数据库中创建数据表 stu(学号 char10、姓名 char 10、专业 char 20)
create table stu
(
sno char(10),
name char(10),
major char(20)
);
desc stu;

#4.grd(学号 char 10、课程 char 15、成绩 int);
create table grd
(
sno char(10),
course char(10),
score int
);
desc grd;

5.为 stu 表姓名字段添加非空约束
alter table stu modify name char(10) not null;
desc stu;


5.1 grd 表成绩字段添加无符号约束
alter table grd modify score int unsigned;
show create table grd;

#5.2两表建立外键约束;
alter table stu modify sno char(10) not null primary key;
alter table grd add constraint fk_stu1 foreign key(sno) references stu(sno);
desc grd;


6、为两张表各插入不少于 3 条完整记录,其中必须包含自己的学号、姓名信息;
#插入学生表
Insert into stu values('001','胡汉三','软件技术');
Insert into stu values('002','伍六一','软件技术');
Insert into stu values('003','赵日天','软件技术');
#查询学生表
select * from stu;
#插入成绩表
Insert into grd values('001','MySQL数据库','99');
Insert into grd values('002','MySQL数据库','88');
Insert into grd values('003','MySQL数据库','66');
Insert into grd values('001','python','100');
Insert into grd values('002','python','99');
Insert into grd values('003','python','60');
#查询成绩表
select * from grd;


8、使用分组查询,查看每门课程的最高分和最低分:
select course,max(score) as 最高分,min(score) as 最低分 from grd GROUP BY course;

9.创建视图,视图中含有学号、专业信息,通过该视图查询学习某专业的学号:
#创建
create view v_view1(sno,major)
as
select sno,major from stu;
#通过视图查询对应专业的学号
select sno from v_view1
where major = '软件技术';

未完待续~~~
评论区