错误更新中的重复条目

时间:2014-03-20 01:13:50

标签: mysql sql-update duplicates

我的表ams2有3个PK toid,formid,sendat

问题是我想要更新到表中我有错误的重复条目

表格结构:

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'

错误消息:

Error Code: 1062. Duplicate entry '1-2-2014-03-20 02:01:53' for key 'PRIMARY'

我希望mySQL查询编辑只是readit列而不是默认编辑其他列

请帮助!!


I FUND SOLUTION

使用alter table并修改sendat并删除此选项ON UPDATE CURRENT_TIMESTAMP

让它像这样 sendat` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP

0 个答案:

没有答案