The new principle established partition is equivalent to the establishment of a temporary table, and then copy the original data table, then delete the original table, the final table will be temporarily renamed the original show, partition has been constructed.
- Procedure code
--创建临时表
CREATE TABLE temp_Stock_Received
(
Stock_ID NUMBER PRIMARY KEY,
Stock_Date DATE,
Cost NUMBER(20,2) NOT NULL
)
PARTITION BY RANGE(Stock_Date)
(
PARTITION P1 VALUES LESS THAN(TO_DATE('2019-04-1','YYYY-MM-DD')),
PARTITION P2 VALUES LESS THAN(TO_DATE('2019-07-1','YYYY-MM-DD')),
PARTITION P3 VALUES LESS THAN(TO_DATE('2019-10-1','YYYY-MM-DD')),
PARTITION P4 VALUES LESS THAN(MAXVALUE)
);
--复制原始表数据
INSERT INTO temp_Stock_Received
SELECT * FROM Stock_Received;
--删除原始表
DROP TABLE Stock_Received;
--修改临时表名称
RENAME temp_Stock_Received TO Stock_Received;