To alter a regular table into a partitioned one, use the ALTER TABLE statement. Three partitioning methods can be used with the ALTER TABLE statement. The data in the existing table are moved to and stored in each partition according to the partition definition.
ALTER {TABLE | CLASS} table_name
PARTITION BY {RANGE | HASH | LIST } ( <partition_expression> )
( PARTITION partition_name VALUES LESS THAN { MAXVALUE | ( <partition_value_option> ) }
| PARTITION partition_name VALUES IN ( <partition_value_option list) > ]
| PARTITION <UNSINGED_INTEGER> )
<partition_expression>
expression_
<partition_value_option>
literal_
The following are examples of altering the record table into a range, list and hash table respectively.
ALTER TABLE record PARTITION BY RANGE (host_year)
( PARTITION before_1996 VALUES LESS THAN (1996),
PARTITION after_1996 VALUES LESS THAN MAXVALUE);
ALTER TABLE record PARTITION BY list (unit)
( PARTITION time_record VALUES IN ('Time'),
PARTITION kg_record VALUES IN ('kg'),
PARTITION meter_record VALUES IN ('Meter'),
PARTITION score_record VALUES IN ('Score') );
ALTER TABLE record
PARTITION BY HASH (score) PARTITIONS 4;
If there is data that does not satisfy the partition condition, partitions cannot be defined.