1.创建本地分区列表索引

create table test(id number,varchar2(100));

create index idx123 on test(id) local;

本地索引是其分区方式与所在基础表的分区方式一模一样的索引,本地索引的每一个分区仅对应于其所在基础表的一个分区

创建表空间

create tablespace ts1 logging datafile '/oracle/app/oradata/TEST/ts1.dbf' size 100M;

create tablespace ts2 logging datafile '/oracle/app/oradata/TEST/ts2.dbf' size 100M;

create tablespace ts3 logging datafile '/oracle/app/oradata/TEST/ts3.dbf' size 100M;

create tablespace ts4 logging datafile '/oracle/app/oradata/TEST/ts4.dbf' size 100M;

创建范围分区表

create table test (id nmber,data varchar2(100))

partition by range (id)

partition p1 values less than (10000) tablespace ts1,

partition p2 values less than (20000) tablespace ts2,

partition p3 values less than  (50000) tablespace ts3,

partition p4 values less than (maxvalue) tablespace ts4

);

select dbms_metadata.get_ddl('INDEX','I_ID','ROBINSON') index_name from dual;

本地索引只支持分区区内的唯一性,无法支持表上的唯一性,因此用本地索引去做表的唯一约束则约束中必须包括分区列键

全局索引global  index

一个分区索引指向n个表分区,一个表分区也能指向n个索引分区,

create index idx123 on test (id ) global partition by range(id)

(

partition idx_1 values less than (10000) tablespace ts1,

partition idx_2 values less than (25000) tablespace ts2,

partition idx_3 values less than (50000) tablespace ts3,

partition idx_4 values less than (maxvalue) tablespace ts4);

 

使得数据处理的更加灵活,能将指定各分区的表空间,使能够对单个分区进行备份和恢复,对大型的数据减少了维护时间。