分区表和分区索引的创建案例
2011-05-31 13:48 Tracy. 阅读(540) 评论(0) 编辑 收藏 举报--帐号信息表
CREATE TABLE TB_U_ACCOUNT
(
ACCOUNT_ID NUMBER(20),
ACCOUNT_BALANCE_TOTAL NUMBER(13,2),
ACCOUNT_BALANCE NUMBER(13,2),
DAY_MONEY NUMBER(13,2),
MONTH_MONEY NUMBER(13,2),
ADD_DAY VARCHAR2(8),
ADD_MONTH VARCHAR2(6),
ACCOUNT_REGISTER_TIME DATE,
ACCOUNT_LAST_CONSUME_TIME DATE,
ACCOUNT_STATUS NUMBER(1)
)
PARTITION BY HASH(account_id)
(
PARTITION PART_ACCOUNT_01 TABLESPACE TBS_BILLING01,
PARTITION PART_ACCOUNT_02 TABLESPACE TBS_BILLING01,
PARTITION PART_ACCOUNT_03 TABLESPACE TBS_BILLING01,
PARTITION PART_ACCOUNT_04 TABLESPACE TBS_BILLING01,
PARTITION PART_ACCOUNT_05 TABLESPACE TBS_BILLING01
);
--创建全局分区索引
CREATE INDEX PK_PARTITION_TB_U_ACCOUNT ON TB_U_ACCOUNT(ACCOUNT_ID)
PARALLEL
global PARTITION BY HASH(ACCOUNT_ID)
(
PARTITION IDX_ACCOUNT_ID_GLOBAL_01 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_ACCOUNT_ID_GLOBAL_02 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_ACCOUNT_ID_GLOBAL_03 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_ACCOUNT_ID_GLOBAL_04 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_ACCOUNT_ID_GLOBAL_05 TABLESPACE TBS_BILLING_INDX01
);
--创建主键
alter table TB_U_ACCOUNT
add constraint PK_PARTITION_TB_U_ACCOUNT primary key (ACCOUNT_ID) using index;
--帐户交易流水表
CREATE TABLE TB_L_BUSI_LOG
(
LOG_ID VARCHAR2(14),
OP_TIME DATE,
BUS_TYPE VARCHAR(2),
ACCOUNT_ID VARCHAR2(20),
USER_ID VARCHAR2(20),
MSISDN VARCHAR2(11),
CHANNEL_ID VARCHAR2(8),
CPID VARCHAR2(6),
CP_SERVICE_ID VARCHAR2(11),
CONSUME_CODE VARCHAR2(8),
MONEY NUMBER(8,2),
POINT NUMBER(8,2),
POINT_FACT NUMBER(8,2),
PREFERENTIAL_PRICE NUMBER(1),
PREFERENTIAL_RULE_ID NUMBER(6),
RESULT NUMBER(6)
)
PARALLEL
PARTITION BY RANGE(op_time) SUBPARTITION BY HASH(account_id)
(
PARTITION PART_BUSI_200704 VALUES LESS THAN(TO_DATE('2007-5-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING01,
PARTITION PART_BUSI_200705 VALUES LESS THAN(TO_DATE('2007-6-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING01,
PARTITION PART_BUSI_200706 VALUES LESS THAN(TO_DATE('2007-7-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING01,
PARTITION PART_BUSI_200707 VALUES LESS THAN(TO_DATE('2007-8-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING01,
PARTITION PART_BUSI_200708 VALUES LESS THAN(TO_DATE('2007-9-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING01,
PARTITION PART_BUSI_200709 VALUES LESS THAN(TO_DATE('2007-10-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING01,
PARTITION PART_BUSI_200710 VALUES LESS THAN(TO_DATE('2007-11-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING01
);
--创建全局分区索引(op_time)
CREATE INDEX IDX_BUSI_GLOBAL_DATE ON TB_L_BUSI_LOG(op_time)
PARALLEL
GLOBAL PARTITION BY RANGE(op_time)
(
PARTITION IDX_BUSI_GLOBAL_DATE_200704 VALUES LESS THAN(TO_DATE('2007-5-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_BUSI_GLOBAL_DATE_200705 VALUES LESS THAN(TO_DATE('2007-6-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_BUSI_GLOBAL_DATE_200706 VALUES LESS THAN(TO_DATE('2007-7-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_BUSI_GLOBAL_DATE_200707 VALUES LESS THAN(TO_DATE('2007-8-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_BUSI_GLOBAL_DATE_200708 VALUES LESS THAN(TO_DATE('2007-9-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_BUSI_GLOBAL_DATE_200709 VALUES LESS THAN(TO_DATE('2007-10-01','YYYY-MM-DD')) TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_BUSI_GLOBAL_DATE_200710 VALUES LESS THAN(MAXVALUE) TABLESPACE TBS_BILLING_INDX01
);
--创建全局分区索引(account_id)
CREATE INDEX INDX_PARTITION_TB_L_BUSI_LOG ON TB_L_BUSI_LOG(ACCOUNT_ID)
PARALLEL
global PARTITION BY HASH(ACCOUNT_ID)
(
PARTITION IDX_TB_L_BUSI_LOG_GLOBAL_01 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_TB_L_BUSI_LOG_GLOBAL_02 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_TB_L_BUSI_LOG_GLOBAL_03 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_TB_L_BUSI_LOG_GLOBAL_04 TABLESPACE TBS_BILLING_INDX01,
PARTITION IDX_TB_L_BUSI_LOG_GLOBAL_05 TABLESPACE TBS_BILLING_INDX01
);
/*
--若需新建时间分区可采用如下的语句
ALTER TABLE TB_L_BUSI_LOG
ADD PARTITION PART_BUSI_200711 VALUES LESS THAN(TO_DATE('2007-12-01','YYYY-MM-DD'))
TABLESPACE TBS_BILLING01;
*/
本文来自博客园,作者:Tracy.,转载请注明原文链接:https://www.cnblogs.com/tracy/archive/2011/05/31/2064282.html