Saya melakukan INSERT ... ON DUPLICATE KEY UPDATE
untuk a PRIMARY KEY
di tabel berikut:
DESCRIBE users_interests;
+------------+---------------------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------------------------+------+-----+---------+-------+
| uid | int(11) | NO | PRI | NULL | |
| iid | int(11) | NO | PRI | NULL | |
| preference | enum('like','dislike','ignore') | YES | | NULL | |
+------------+---------------------------------+------+-----+---------+-------+
Namun, meskipun nilai ini harus unik, saya melihat 2 baris terpengaruh.
INSERT INTO users_interests (uid, iid, preference) VALUES (2, 2, 'like')
ON DUPLICATE KEY UPDATE preference='like';
Query OK, 2 rows affected (0.04 sec)
Mengapa ini terjadi?
EDIT
Sebagai perbandingan, lihat kueri ini:
UPDATE users_interests SET preference='like' WHERE uid=2 AND iid=2;
Query OK, 1 row affected (0.44 sec)
Rows matched: 1 Changed: 1 Warnings: 0