Mysql 更新中出现重复条目错误

Mysql 更新中出现重复条目错误,mysql,sql-update,duplicates,Mysql,Sql Update,Duplicates,我有带3个PK toid、formid和sendat的ams2表 问题是我想更新到表中,因为我有一个重复的条目 表结构器: CREATE TABLE `ams2` ( `toid` int(11) NOT NULL DEFAULT '0', `fromid` int(11) NOT NULL, `name` varchar(50) DEFAULT NULL, `message` text, `ismsl` tinyint(1) DEFAULT '0', `sendat`

我有带3个PK toid、formid和sendat的ams2表

问题是我想更新到表中,因为我有一个重复的条目

表结构器:

CREATE TABLE `ams2` (
  `toid` int(11) NOT NULL DEFAULT '0',
  `fromid` int(11) NOT NULL,
  `name` varchar(50) DEFAULT NULL,
  `message` text,
  `ismsl` tinyint(1) DEFAULT '0',
  `sendat` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `readit` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`toid`,`fromid`,`sendat`),
  KEY `ams2_ibfk_1` (`fromid`,`name`),
  CONSTRAINT `ams2_ibfk_1` FOREIGN KEY (`fromid`, `name`) REFERENCES `allclient` (`id`, `name`),
  CONSTRAINT `ams2_ibfk_2` FOREIGN KEY (`toid`) REFERENCES `allclient` (`id`)
) 



update ams2
    set readit =true
    where fromid=2 and toid =1 and sendat <= '2014-03-16 18:07:37'
我希望mySQL查询编辑只是readit列,默认情况下不编辑其他列

请帮忙


我提供资金解决方案 使用alter table和modify sendat,并在更新当前时间戳时删除此选项

就这样吧
sendat`timestamp NOT NULL DEFAULT CURRENT_timestamp

如果要插入到表中,为什么要使用
update
语句?键不在sendat上。您在三个字段上有一个唯一的约束,我可以看到值1、2、2014-03-20 02:01:53,这导致了重复。您是否有包含readit字段的唯一索引?可能重复
Error Code: 1062. Duplicate entry '1-2-2014-03-20 02:01:53' for key 'PRIMARY'