一、 索引
- 作用:加快查询速度
- 创建
1) 创建表同时创建索引
create table student1
(sno char(4),
sname char(20),
index ix_sno(sno asc));
2) 在已经存在的表上创建索引
create index ix_sno on student(sno desc); - 查看 show index from student;
- 删除
drop index ix_sno on student1;
二、 视图 - 定义:从一个或多个基本表或视图中导出的虚表。
- 作用
- 简化对数据的操作。
- 自定义数据。
- 数据集中显示。
- 导入和导出数据。
- 合并分割数据。
- 安全机制。
- 创建(修改)
Create(alter) view 名字
As
Select语句
举例
创建视图v1,其内容包括学生学号、姓名、课程号、课程名、成绩;
create view v1
as
select student.sno,sname,course.cno,cname,grade
from student join sc on student.sno = sc.sno
join course on sc.cno = course.cno; - 查看
- 使用
select *
from v1
where sname = ‘刘晨’;
对视图的增删改是有限制的
出错实例:
insert into v1
v