索引与视图

索引

1.作用:提升查询效率

  1. 创建索引

    create index 索引名 on 表名(字段名)

create index index_student_sid on student(sid);
  1. 删除索引
    drop index 索引名

2.特点:

  1. 显示的创建,隐式的执行
  2. oracle新建表会将该表的主键自动创建索引

视图

1.创建视图
create or replace view 视图名 as 查询语句(对外提供的内容) from 真实表名

视图名映射了一个查询语句

create or replace view stu as select sid 学号,sname 姓名 from student;

2.删除视图 drop view 视图名

drop view stu;

3.视图的特点

  1. 保护真实表,隐藏核心字段的数据
  2. 在视图中的操作会映射执行到真实表中
  3. 可以收到开启视图只读模式 使用关键字 with read only
 create or replace view stu2 as select sid,sname from student with read only;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章