首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

oracle 目录

2012-09-03 
oracle索引oracle的索引分为5种:唯一索引,组合索引,反向键索引,位图索引,基于函数的索引?创建索引的标准语

oracle 索引

oracle的索引分为5种:唯一索引,组合索引,反向键索引,位图索引,基于函数的索引

?

创建索引的标准语法:

CREATE INDEX 索引名 ON 表名 (列名)

索引是建立在表的一列或多个列上的辅助对象,目的是加快访问表中的数据。具体来说:

ROWID存储了row在数据文件中的具体位置:64位编码的数据,A-Z, a-z, 0-9, +, 和 /;  row在数据块中的存储方式:比如,ROwID=OOOOOOFFFBBBBBBRRR,含义是:  

OOOOOO:data object number, 对应dba_objects.data_object_id;

FFF:file#, 对应v$datafile.file#;

BBBBBB:block#;

RRR:row#;

4.3???? 消除磁盘排序

表:emp

  

  目标:查询Frank的工资salary

  建立索引:create index emp_name_idx on emp(name);
?

?

 

?

创建索引时指定表空间,特别是在建立主键时,应明确指定表空间;合理设定pctfress,注意:不能给索引指定pctused;。估计索引的大小和合理地设置存储参数,默认为表空间大小,或initial与next设置成一样大。

对大表可以采用并行创建索引,在并行创建索引时,存储参数被每个查询服务器进程分别使用,例如:initial为1M,并行度为8,则创建索引期间至少要消耗8M空间;

  create index index_name on table_name(field_name)
  tablespace tablespace_name
  pctfree 5
  initrans 2
  maxtrans 255
  storage
  (
  minextents 1
  maxextents 16382
  pctincrease 0
  );  

  ???????? 常用与UPPER、LOWER、TO_CHAR(date)等函数分类上,例:create index idx_func on emp (UPPER(ename)) tablespace tablespace_name;

对基数较小,且基数相对稳定的列建立索引时,首先应该考虑位图索引,例:  create bitmap index idx_bitm on class (classno) tablespace tablespace_name;

可以用create unique index语句来创建唯一索引,例:create unique index dept_unique_idx on dept(dept_no) tablespace idx_1;

可以用using index字句,为与unique和primary key约束相关的索引,例如:  alter table table_name add constraint PK_primary_keyname primary key (field_name)  using index tablespace tablespace_name;据产生大量db file sequential read锁等待;

?

-----------------------------------------

索引分类:

唯一索引,作用是数据约束,保证数据唯一,还有就是数据索引,提高查询效率 一般索引,只有数据索引的作用。


唯一索引:

    ?oracle  目录oracle  目录
      create unique index idx_employee_empname on employee(empname);


      一般索引:

        ?oracle  目录oracle  目录
          create index idx_employee_address on employee(address);create unique index idx_employee_field1_field2 on employee(field1,field2);


          函数索引:

            ?oracle  目录oracle  目录
              create index idx_product_nvl_price on product(nvl(price,0.0));


              删除索引:

                ?oracle  目录oracle  目录
                  drop index idx_employee_empname;


                  指定索引表空间

                    ?oracle  目录oracle  目录
                      create index idx_employee_address on employee(address) tablespace indexs;


                      查看索引

                        ?oracle  目录oracle  目录
                          select?*?from?user_indexes?where?table_name?=?'SHOP_PD'??

热点排行