MySQL语法如何创建分区表、查询分区表

纸扎戏偶
//创建分区表
CREATE TABLE orders (
  id INT PRIMARY KEY AUTO_INCREMENT,
  order_no VARCHAR(20),
  order_date DATE
) PARTITION BY RANGE (YEAR(order_date)) (
  PARTITION p0 VALUES LESS THAN (2020),
  PARTITION p1 VALUES LESS THAN (2021),
  PARTITION p2 VALUES LESS THAN (2022),
  PARTITION p3 VALUES LESS THAN (2023),
  PARTITION p4 VALUES LESS THAN MAXVALUE
);

//查询分区表
SELECT * FROM orders PARTITION (p1) WHERE YEAR(order_date) = 2022;
文章版权声明:除非注明,否则均为我爱教程术原创文章,转载或复制请以超链接形式并注明出处。