ORACLE索引的作用及用法

来源:互联网 发布:软件使用 编辑:程序博客网 时间:2024/05/17 04:55

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

create index <index_name> on <table_name>(<column_name>) [tablespace<tablespace_name>];

2、重置索引

alter index <index_name> rebuild;

3、删除索引

drop index <index_name>

实例:

create table test asselect 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) txtfrom dualconnect by level<=20000000;select count(id) from test;select * from test where txt='2W8U82V49FKZYK0JQETF';drop table  test;

二、索引的分类
1、普通索引

create index index_text_txt on test(txt);

2、唯一索引 Oracle 自动在表的主键上创建唯一索引

create unique index <index_name> on <index_name>(<coiumn_name>);

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

create bitmap index <index_name> on <table_name>(<column_name>)

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

实例:create index <index_name> on <table_name>(<column_name1><column_name2>)

5、基于函数索引

create index <index_name> on <table_name>(<function_name>(<column_name>));

6、反向键索引

create index <index_name> on <table_name>(column_name) reverse;
0 0
原创粉丝点击