五、分区表操作
- CREATE TABLE t1 (
- id INT,
- year_col INT
- )
- PARTITION BY RANGE (year_col) (
- PARTITION p0 VALUES LESS THAN (1991),
- PARTITION p1 VALUES LESS THAN (1995),
- PARTITION p2 VALUES LESS THAN (1999)
- );
复制代码
1、ADD PARTITION (新增分区)
- ALTER TABLE t1 ADD PARTITION (PARTITION p3 VALUES LESS THAN (2002));
复制代码
2、DROP PARTITION (删除分区)
- ALTER TABLE t1 DROP PARTITION p0, p1;
复制代码
3、TRUNCATE PARTITION(截取分区)
- ALTER TABLE t1 TRUNCATE PARTITION p0;
- ALTER TABLE t1 TRUNCATE PARTITION p1, p3;
复制代码
4、COALESCE PARTITION(合并分区)
- CREATE TABLE t2 (
- name VARCHAR (30),
- started DATE
- )
- PARTITION BY HASH( YEAR(started) )
- PARTITIONS 6;
复制代码
- ALTER TABLE t2 COALESCE PARTITION 2;
复制代码
5、REORGANIZE PARTITION(拆分/重组分区)
|
|