MYSQL的分区字段,必须包含在主键字段内

在对表进行分区时,如果分区字段没有包含在主键字段内,如表A的主键为ID,分区字段为createtime ,按时间范围分区,代码如下:  www.2cto.com  

CREATE TABLE T1 (

     id int(8) NOT NULL AUTO_INCREMENT,

     createtime datetime NOT NULL,

      PRIMARY KEY (id)

) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8

PARTITION BY RANGE(TO_DAYS (createtime))

(

PARTITION p0 VALUES LESS THAN (TO_DAYS('2010-04-15')),

PARTITION p1 VALUES LESS THAN (TO_DAYS('2010-05-01')),

PARTITION p2 VALUES LESS THAN (TO_DAYS('2010-05-15')),

PARTITION p3 VALUES LESS THAN (TO_DAYS('2010-05-31')),

PARTITION p4 VALUES LESS THAN (TO_DAYS('2010-06-15')),

PARTITION p19 VALUES LESS ThAN  MAXVALUE);

错误提示:#1503


原载于:联动北方

全文:http://bbs.landingbj.com/t-0-248923-1.html

你可能感兴趣的:(mysql)