MySQL第四次作业(索引、视图)

要求:

1.修改student 表中年龄(sage)字段属性,数据类型由int 改变为smallint

sql 复制代码
desc student;
desc  course;
desc  Score;
sql 复制代码
alter table student modify Sage smallint;

2.为Course表中Cno 课程号字段设置索引,并查看索引

sql 复制代码
create index index_cno on course(Cno);
show index from course\G

3.为SC表建立按学号(sno)和课程号(cno)组合的升序的主键索引,索引名为SC_INDEX

sql 复制代码
create unique index SC_INDEX ON sc(Sno,Cno asc);
 show index from sc\G

4.创建一视图 stu info,查询全体学生的姓名,性别,课程名,成绩

sql 复制代码
select  Sname,Ssex,Cname,Score  from student join  sc on student.Sno=sc.Sno join course on sc.Cno=course.Cno;
create or replace view  stu_info as select  Sname,Ssex,Cname,Score  from student join  sc on student.Sno=sc.Sno join course on sc.Cno=course.Cno;

5.删除所有索引

sql 复制代码
show tables;
+---------------------------+
| Tables_in_mydb15_indexstu |
+---------------------------+
| course                    |
| sc                        |
| stu_info                  |
| student                   |
+---------------------------+
4 rows in set (0.00 sec)
drop index  index_cno  on course;
drop index SC_INDEX on sc;
相关推荐
TDengine (老段)13 分钟前
TDengine Python 连接器进阶指南
大数据·数据库·python·物联网·时序数据库·tdengine·涛思数据
赵渝强老师21 分钟前
【赵渝强老师】OceanBase的配置文件与配置项
数据库·oceanbase
玖日大大1 小时前
OceanBase SeekDB:AI 原生数据库的技术革命与实践指南
数据库·人工智能·oceanbase
高溪流2 小时前
3.数据库表的基本操作
数据库·mysql
alonewolf_992 小时前
深入剖析MySQL锁机制与MVCC原理:高并发场景下的数据库核心优化
数据库·mysql
一 乐3 小时前
绿色农产品销售|基于springboot + vue绿色农产品销售系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·后端·宠物
黄宝康3 小时前
sqlyog密钥亲测有效
mysql
Codeking__3 小时前
Redis初识——什么是Redis
数据库·redis·mybatis
YIN_尹3 小时前
【MySQL】数据类型(上)
android·mysql·adb
k***1953 小时前
Spring 核心技术解析【纯干货版】- Ⅶ:Spring 切面编程模块 Spring-Instrument 模块精讲
前端·数据库·spring