mysql的建表分区sql语句
时间: 2023-12-08 09:39:38 浏览: 88
建表sql语句(mysql)
5星 · 资源好评率100%
以下是MySQL的建表分区SQL语句的示例:
```mysql
CREATE TABLE sales (
id INT NOT NULL,
region VARCHAR(100),
country VARCHAR(100),
item_type VARCHAR(100),
sales_channel VARCHAR(100),
order_date DATE,
order_id INT,
units_sold INT,
unit_price DECIMAL(10,2),
total_price DECIMAL(10,2)
)
PARTITION BY RANGE (YEAR(order_date)) (
PARTITION p0 VALUES LESS THAN (2010),
PARTITION p1 VALUES LESS THAN (2011),
PARTITION p2 VALUES LESS THAN (2012),
PARTITION p3 VALUES LESS THAN (2013),
PARTITION p4 VALUES LESS THAN (2014),
PARTITION p5 VALUES LESS THAN (2015),
PARTITION p6 VALUES LESS THAN (2016),
PARTITION p7 VALUES LESS THAN (2017),
PARTITION p8 VALUES LESS THAN (2018),
PARTITION p9 VALUES LESS THAN (2019),
PARTITION p10 VALUES LESS THAN MAXVALUE
);
```
上述示例中,使用了`PARTITION BY RANGE`语句来指定分区方式,按照订单日期的年份进行分区。然后使用`PARTITION`语句来指定每个分区的范围。
阅读全文