我还没有真正了解 REPLACE INTO 的工作原理。据我了解,如果任何值与旧行值匹配,它将删除该行并插入更新的数据?
例如我有这张桌子
+-------------+----------------+------+---------+
| name | value | city | address |
+-------------+----------------+------+---------+
| First book | a value | NY | NULL |
| second book | an other value | LA | NULL |
+-------------+----------------+------+---------+
现在我想改变第二本书的城市并执行
REPLACE INTO book(name,value,city) VALUES ('second book','an other value','CA');
注意:名称和值是相同的,但 mysql 仍然插入一个新行?
+-------------+----------------+------+---------+
| name | value | city | address |
+-------------+----------------+------+---------+
| First book | a value | NY | NULL |
| second book | an other value | LA | NULL |
| second book | an other value | CA | NULL |
+-------------+----------------+------+---------+