在MySQL中遇到ON DUPLICATE KEY UPDATE的麻烦。以下是我试图运行的查询。
INSERT INTO `Overall` ( `rsn` , `starting_xp` , `starting_lvl` ) VALUES ( 'iWader' , '195843626' , '2281' ) ON DUPLICATE KEY UPDATE `current_xp` = '195843626' AND `current_lvl` = '2281'
这是我表格的结构
CREATE TABLE IF NOT EXISTS `overall` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`rsn` varchar(12) NOT NULL,
`starting_xp` int(10) unsigned NOT NULL,
`starting_lvl` int(10) unsigned NOT NULL,
`current_xp` int(10) unsigned NOT NULL,
`current_lvl` int(10) unsigned NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `rsn` (`rsn`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;
答案 0 :(得分:1)
试试这个:
INSERT INTO `Overall` ( `rsn` , `starting_xp` , `starting_lvl` ) VALUES ( 'iWader' , '195843626' , '2281' ) ON DUPLICATE KEY UPDATE `current_xp` = '195843626', `current_lvl` = '2281';
AND
子句中的UPDATE
错误。 AND
用于布尔表达式,例如“is foo true AND
bar true?”
在这里,您要更新列current_xp,current_lvl。
答案 1 :(得分:1)
在ON DUPLICATE KEY UPDATE
后,您不需要在字段中使用and
,而是使用,
。
ON DUPLICATE KEY UPDATE `current_xp` = '195843626', `current_lvl` = '2281'