索引 基本

一、索引的几种常用用法
1、创建索引

create index <index_name> on <table_name>(<column_name>) [tablespace<tablespace_name>];
1
2、重置索引

alter index <index_name> rebuild;
1
3、删除索引

drop index <index_name>
1
实例:

create table test as
select rownum as id,
to_char(sysdate + rownum/24/3600,'yyyy-mm-dd hh24:mi:ss') as ttime,
trunc(dbms_random.value(0,100)) as random_id,
dbms_random.string('x',20) txt
from dual
connect by level<=20000000;
select count(id) from test;
select * from test where txt='2W8U82V49FKZYK0JQETF';
drop table test;
1
2
3
4
5
6
7
8
9
10
二、索引的分类
1、普通索引

create index index_text_txt on test(txt);
1
2、唯一索引 Oracle 自动在表的主键上创建唯一索引

create unique index <index_name> on <index_name>(<coiumn_name>);
1
3、位图索引
作用范围及优点:
1、位图索引适合创建在低级数列(重复的数值多,如性别)上
2、减少响应时间
3、节省空间占用

create bitmap index <index_name> on <table_name>(<column_name>)
1
4、组合索引
作用范围及优点:
1、组合索引是在表的多个列上创建的索引
2、索引中的顺序是任意的
3、如果SQL语言的WHERE子句中引用了组合索引的所有或大多数列,则可以提高检索速度

实例:
create index <index_name> on <table_name>(<column_name1><column_name2>)
1
2
5、基于函数索引

create index <index_name> on <table_name>(<function_name>(<column_name>));
1
6、反向键索引

create index <index_name> on <table_name>(column_name) reverse;
---------------------
作者:Mars_hero
来源:CSDN
原文:https://blog.csdn.net/qq_34895697/article/details/52425289
版权声明:本文为博主原创文章,转载请附上博文链接!

原文地址:https://www.cnblogs.com/kakaisgood/p/10394326.html