版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuxin6866/article/details/75364921
mysql> select * from states;
+----+---------+------------+
| id | state | population |
+----+---------+------------+
| 1 | Alabama | 4822026 |
| 2 | bbb | 33444 |
| 3 | Alabama | 4822024 |
| 4 | ccc | 44 |
| 5 | ddd | 5 |
+----+---------+------------+
5 rows in set (0.00 sec)
mysql> INSERT INTO states (id, population) VALUES (4, 444), (5, 555) ON DUPLICATE KEY UPDATE id=values(id), population=values(population);
Query OK, 4 rows affected (0.00 sec)
Records: 2 Duplicates: 2 Warnings: 0
mysql> select * from states; +----+---------+------------+
| id | state | population |
+----+---------+------------+
| 1 | Alabama | 4822026 |
| 2 | bbb | 33444 |
| 3 | Alabama | 4822024 |
| 4 | ccc | 444 |
| 5 | ddd | 555 |
+----+---------+------------+