其他分享
首页 > 其他分享> > 给已有的表分区

给已有的表分区

作者:互联网

-- 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;

 

标签:temp,--,分区,time,test,table,create,已有
来源: https://www.cnblogs.com/zslb/p/14441463.html