when using insert on duplicate key update to insert duplicate data, only the data of the duplicate unique index is updated, and the number of affected rows is returned as 2 rows.
looking up data means that the operation will perform two operations:
1.insert table attempts to insert [try to insert, there is duplicate data, and there should be no table data change at this time]
2.update updates the value of the unique index [change rows 1]
, so I"m confused about where the other change occurs. Ask a question for the first time, and ask the boss to solve the puzzle
related codes
/ / Please paste the code text below (do not replace the code with pictures)
table structure
CREATE TABLE test1
(
id INT AUTO_INCREMENT
PRIMARY KEY,
name VARCHAR(20) NOT NULL,
stu_id INT NOT NULL
)
ENGINE = InnoDB;
id unique
insert into test1 VALUES ("4","","2") on DUPLICATE KEY UPDATE stu_id=stu_id+1;
commit;