1-为什么要用索引?
快速查找数据库表中某条数据;减少I/O操作
2-什么场景下使用索引?
对需要进行条件查询的列使用索引
3-列举四类索引?
B树索引、位图索引、反向键索引、函数索引
4-创建索引
--B树索引
create index emp_teptno_index on emp(deptno)--对emp表在deptno上创建索引
pctfree 25 --为将来Insert操作预留的空间
tablespace users;--索引段所在表空间
--位图索引
create bitmap index emp_sal_bmp
on emp(sal)
tablespace users;
5-重建索引
alter index emp_teptno_index rebuild;
6-更改索引的表空间
alter index emp_teptno_index rebuild tablespace tbs_gwn;
7-删除索引
删除索引的原因:
(1)如果移动了表中的数据,导致索引中包含过多的存储碎片,此时需要删除并重建索引;
(2)通过一段时间的监视,发现很少有查询会使用到该索引,此时应删除索引,释放空间。
--删除索引
drop index emp_sal_bmp;
8- 如何查询索引信息?
--显示表的所有索引
select * from dba_indexes where owner='scott';
--显示索引列
select * from dba_ind_columns;--所有索引的表列信息
select * from user_ind_columns; 当前用户索引的表列信息
--显示索引段位置极其大小
select * from user_ind_expressions;