CREATE TABLE `d_s_rep` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`p_id` bigint(20) NOT NULL,
`i_id` bigint(20) NOT NULL,
`d_id` bigint(20) NOT NULL,
`s_id` bigint(20) NOT NULL,
`t_id` bigint(20) NOT NULL DEFAULT '0',
`as_id` bigint(20) NOT NULL,
`ccount` bigint(20) DEFAULT '0',
`dcount` bigint(20) NOT NULL DEFAULT '0',
`icount` bigint(20) DEFAULT '0',
`di` bigint(20) NOT NULL DEFAULT '0',
`dhi` bigint(20) NOT NULL DEFAULT '0',
`r` decimal(25,8) DEFAULT '0.00000000',
`f_date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`t_date` datetime DEFAULT NULL,
`t_stamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`,`f_date`),
KEY `d_id` (`d_id`),
KEY `p_id` (`p_id`),
KEY `f_date` (`f_date`),
KEY `i_id` (`i_id`),
KEY `s_id` (`s_id`),
KEY `t_id` (`t_id`),
KEY `as_id` (`as_id`)
) ENGINE=InnoDB AUTO_INCREMENT=11064336 DEFAULT CHARSET=latin1 /*!50100 PARTITION BY RANGE (TO_DAYS(f_date)) (PARTITION p2009OLD VALUES LESS THAN (733863) ENGINE = InnoDB, PARTITION p2009Q2 VALUES LESS THAN (733954) ENGINE = InnoDB, PARTITION p2009Q3 VALUES LESS THAN (734046) ENGINE = InnoDB, PARTITION p2009Q4 VALUES LESS THAN (734138) ENGINE = InnoDB, PARTITION p2010Q1 VALUES LESS THAN (734228) ENGINE = InnoDB, PARTITION p2010Q2 VALUES LESS THAN (734319) ENGINE = InnoDB, PARTITION p2010Q3 VALUES LESS THAN (734411) ENGINE = InnoDB, PARTITION p2010M10 VALUES LESS THAN (734442) ENGINE = InnoDB, PARTITION p2010M11 VALUES LESS THAN (734472) ENGINE = InnoDB, PARTITION p2010M12 VALUES LESS THAN (734503) ENGINE = InnoDB, PARTITION p2011M01 VALUES LESS THAN (734534) ENGINE = InnoDB, PARTITION p2011M02 VALUES LESS THAN (734562) ENGINE = InnoDB, PARTITION p2011M03 VALUES LESS THAN (734593) ENGINE = InnoDB, PARTITION p2011M04 VALUES LESS THAN (734623) ENGINE = InnoDB, PARTITION p2011M05 VALUES LESS THAN (734654) ENGINE = InnoDB, PARTITION p2011M06 VALUES LESS THAN (734684) ENGINE = InnoDB, PARTITION p2011M07 VALUES LESS THAN (734715) ENGINE = InnoDB, PARTITION p2011M08 VALUES LESS THAN (734746) ENGINE = InnoDB, PARTITION p2011M09 VALUES LESS THAN (734776) ENGINE = InnoDB, PARTITION p2011M10 VALUES LESS THAN (734807) ENGINE = InnoDB, PARTITION p2011M11 VALUES LESS THAN (734837) ENGINE = InnoDB, PARTITION p2011M12 VALUES LESS THAN (735173) ENGINE = InnoDB)
在上面提到的表中,在代码中插入少量插入查询失败并显示错误
Total Number of diagnostic records: 1
SQLSTATE: 23000
Native Error Code: 1022
[MySQL][ODBC 3.51 Driver][mysqld-5.1.30-community-log]Can't write; duplicate key in table 'd_s_rep'
insert statment“not not”包含id(NOT NULL AUTO_INCREMENT
)和t_stamp(NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)的值。
我在各种论坛上阅读了帖子,但无法解决问题的根本情况。
如果有人可以指导我解决问题
,那将会很有帮助答案 0 :(得分:3)
看起来你正试图设置多个PRIMARY KEY
PRIMARY KEY (id,f_date)
你只能拥有一个PRIMARY KEY,并且你已经将f_date设置为KEY,所以只需删除,f_date 就可以了。
答案 1 :(得分:0)
你可以像下面这样;不要将'f_date'单独声明为
PRIMARY KEY (`id`,`f_date`),
KEY `d_id` (`d_id`),
KEY `p_id` (`p_id`),
KEY `i_id` (`i_id`),
KEY `s_id` (`s_id`),
KEY `t_id` (`t_id`),
KEY `as_id` (`as_id`)