gpt4 book ai didi

mysql - 主必须包括表的分区位置错误中的所有列?

转载 作者:IT老高 更新时间:2023-10-29 00:11:35 28 4
gpt4 key购买 nike

我尝试创建一个具有范围分区的表。但它显示以下错误:

A primary must include all columns in the table's partitioning location.

这是我的 SQL 语句:

CREATE TABLE `tbl_emp_confirmation` (
`fld_id` int(11) NOT NULL AUTO_INCREMENT,
`fldemp_id` varchar(100) DEFAULT NULL,
`fldempname` varchar(100) DEFAULT NULL,
`fldjoindate` varchar(100) DEFAULT NULL,
`fldconfirmdate` Date NOT NULL,
`fldresigndate` varchar(100) DEFAULT NULL,
`fldstatus` varchar(50) DEFAULT NULL,
`fldcon_status` varchar(100) DEFAULT NULL,
UNIQUE KEY `fld_id` (`fld_id`),
KEY `in_empconfirmation` (`fldemp_id`,`fldempname`,`fldjoindate`,`fldconfirmdate`)
) PARTITION BY RANGE ( Month(fldconfirmdate))
(PARTITION p_JAN VALUES LESS THAN (TO_DAYS('2011-01-01')),
PARTITION p_FEB VALUES LESS THAN (TO_DAYS('2011-02-01')),
PARTITION p_MAR VALUES LESS THAN (TO_DAYS('2011-03-01')),
PARTITION p_APR VALUES LESS THAN (TO_DAYS('2011-04-01')),
PARTITION p_MAY VALUES LESS THAN (TO_DAYS('2011-05-01')),
PARTITION p_MAX VALUES LESS THAN MAXVALUE );

最佳答案

您正在使用 fldconfirmdate 对数据进行分区,它是您的 PK 的一部分,但不是您的 UNIQUE KEY fld_id 的一部分。

这是从 MySQL manual 中提取的:

In other words, every unique key on the table must use every column in the table's partitioning expression.

这意味着,将 fldconfirmdate 设置为 UNIQUE KEY 'fld_id' 的一部分将解决问题。

CREATE TABLE `tbl_emp_confirmation` (
`fld_id` int(11) NOT NULL AUTO_INCREMENT,
`fldemp_id` varchar(100) DEFAULT NULL,
`fldempname` varchar(100) DEFAULT NULL,
`fldjoindate` varchar(100) DEFAULT NULL,
`fldconfirmdate` Date NOT NULL,
`fldresigndate` varchar(100) DEFAULT NULL,
`fldstatus` varchar(50) DEFAULT NULL,
`fldcon_status` varchar(100) DEFAULT NULL,
UNIQUE KEY `fld_id` (`fld_id`, `fldconfirmdate`),
KEY `in_empconfirmation` (`fldemp_id`,`fldempname`,`fldjoindate`,`fldconfirmdate`)
) PARTITION BY RANGE ( Month(fldconfirmdate))
(PARTITION p_JAN VALUES LESS THAN (TO_DAYS('2011-01-01')),
PARTITION p_FEB VALUES LESS THAN (TO_DAYS('2011-02-01')),
PARTITION p_MAR VALUES LESS THAN (TO_DAYS('2011-03-01')),
PARTITION p_APR VALUES LESS THAN (TO_DAYS('2011-04-01')),
PARTITION p_MAY VALUES LESS THAN (TO_DAYS('2011-05-01')),
PARTITION p_MAX VALUES LESS THAN MAXVALUE );

关于mysql - 主必须包括表的分区位置错误中的所有列?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11896067/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com