给已有的表分区

-- 1. 重命名
alter table test rename to test_temp;

-- 2. 创建 partition table
create table test
(
ID NUMBER(10) not null,
REMARK VARCHAR2(100),
create_time DATE
)
PARTITION BY RANGE (CREATE_TIME) INTERVAL (numtoyminterval(3, 'month'))
(partition part_t1 values less than(to_date('2021-02-24', 'yyyy-mm-dd')));


-- 3. 创建主键
alter table test_part add constraint test_pk_1 primary key (ID) using INDEX;

-- 4. 将 test_temp 表里的数据迁移到 test 表中
insert into test_temp select * from test;

-- 5. 为分区表设置索引
-- Create/Recreate indexes
create index test_create_time_1 on TEST_PART (create_time);

-- 6. 删除老的 test_temp 表
drop table test_temp purge;

 

posted on 2021-02-24 14:53  爱老虎哟  阅读(138)  评论(0)    收藏  举报

导航