Mysql 为什么这是SQL;“向上插入”;影响两行吗?

Mysql 为什么这是SQL;“向上插入”;影响两行吗?,mysql,sql,Mysql,Sql,我试图写一个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)

我试图写一个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行受影响”。为什么它不是只有一行(如果它命中了insert,我会像预期的那样得到一行影响)

表的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;
在重复密钥更新时,如果发生以下情况,则每行受影响的行值为1 该行将作为新行插入,如果更新了现有行,则为2,并且 如果现有行设置为其当前值,则为0


表中,您有多个唯一键吗?@uuerdo My bad。我在前面指定了id_编号以引用一个特定的id。让我编辑帖子。您是如何创建表的?
id\u编号
是主键/唯一键吗?@sirim是的,它是主键。