我试图写一个upsert,当我按顺序运行这两个查询时:
// The numbers here are arbitrary, but id matches one already existing in db.
SET @id = 1069, @exportid = null, @photoid = 11223344;
INSERT INTO student (id_number, exportid, photoid) VALUES (@id, @exportid, @photoid)
ON DUPLICATE KEY UPDATE exportid = @exportid, photoid = @photoid;
它点击更新并进行一些更改,我得到" 2行受影响"。为什么它不仅仅是一个(如果它碰到插入物,我会按预期影响1行)?
表的CREATE语句,其中包含一堆非键列:
CREATE TABLE `demo`.`student` (
`id_number` varchar(15) NOT NULL DEFAULT '',
`exportid` varchar(20) DEFAULT NULL,
`photoid` varchar(25) DEFAULT NULL,
PRIMARY KEY (`id_number`),
KEY `EXPORTID` (`exportid`),
KEY `NAME` (`last_name`,`student`,`id_number`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
答案 0 :(得分:1)