关于mysql创建表分区,让id自增长、加上主键的话就报错,取消就能创建成功的问题!求大神帮助下!!!

DROPTABLEIFEXISTS`t_meterorigvalue`;CREATETABLE`t_meterorigvalue`(`ID`int(18)NOTNULLA... DROP TABLE IF EXISTS `t_meterorigvalue`;
CREATE TABLE `t_meterorigvalue` (
`ID` int(18) NOT NULL AUTO_INCREMENT ,
`F_OrigValueID` varchar(32) DEFAULT NULL,
`F_BuildID` varchar(16) DEFAULT NULL ,
`F_GateWayID` varchar(2) DEFAULT NULL ,
`F_MeterParamID` varchar(50) DEFAULT NULL ,
`F_MeterID` smallint(6) DEFAULT NULL ,
`F_Address` varchar(16) DEFAULT NULL ,
`F_FunctionID` smallint(6) DEFAULT NULL ,
`F_OrigValue` varchar(32) DEFAULT NULL ,
`F_CollectTime` datetime NOT NULL ,
`F_ReceiveTime` datetime DEFAULT NULL ,
`F_OrigStaCode` varchar(8) DEFAULT NULL,
`F_OrigErrCode` varchar(8) DEFAULT NULL ,
`F_MeterType` smallint(6) DEFAULT NULL,
`F_PackType` smallint(6) DEFAULT NULL ,
`F_ContinusHandle` smallint(6) DEFAULT NULL ,
`F_CalcTime` datetime DEFAULT NULL ,
`F_State` smallint(6) DEFAULT NULL ,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB AUTO_INCREMENT=115169 DEFAULT CHARSET=utf8
/*!50100 PARTITION BY RANGE (month(F_CollectTime)) (
PARTITION p0 VALUES LESS THAN (1) ENGINE = InnoDB,
PARTITION p1 VALUES LESS THAN (2) ENGINE = InnoDB,
PARTITION p2 VALUES LESS THAN (3) ENGINE = InnoDB,
PARTITION p3 VALUES LESS THAN (4) ENGINE = InnoDB,
PARTITION p4 VALUES LESS THAN (5) ENGINE = InnoDB,
PARTITION p5 VALUES LESS THAN (6) ENGINE = InnoDB,
PARTITION p6 VALUES LESS THAN (7) ENGINE = InnoDB,
PARTITION p7 VALUES LESS THAN (8) ENGINE = InnoDB,
PARTITION p8 VALUES LESS THAN (9) ENGINE = InnoDB,
PARTITION p9 VALUES LESS THAN (10)ENGINE = InnoDB,
PARTITION p10 VALUES LESS THAN (11) ENGINE = InnoDB,
PARTITION p11 VALUES LESS THAN MAXVALUE
)*/;

`ID` int(18) NOT NULL AUTO_INCREMENT
PRIMARY KEY (`ID`)
加上这个就会报错
展开
 我来答
聚合智创
2014-12-08 · TA获得超过303个赞
知道小有建树答主
回答量:518
采纳率:80%
帮助的人:252万
展开全部
MySQL主键的限制,每一个分区表中的公式中的列,必须在主键/unique key 中包括
MYSQL的官方文档里是这么说明的
18.5.1. Partitioning Keys, Primary Keys, and Unique Keys
This section discusses the relationship of partitioning keys with primary keys and unique keys. The rule governing this relationship can be expressed as follows: All columns used in the partitioning expression for a partitioned table must be part of every unique key that the table may have.

In other words,every unique key on the table must use every columnin the table's partitioning expression. (This also includes the table's primary key, since it is by definition a unique key. This particular case is discussed later in this section.) For example, each of the following table creation statements is invalid:

解决办法是创建复合主键,将id和你的分区字段创建复合主键..
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式