mysql 中使用 update 同时更新多个字段
程序员文章站
2022-06-01 14:35:06
...
update 表名 set 字段1=新值1, 字段2=新值2, 字段3=新值3, ... where 条件
mysql> select * from tb_person;
+----+----------+-------------+------+------+-------------+---------------------+
| id | name | phone | age | sex | description | create_time |
+----+----------+-------------+------+------+-------------+---------------------+
| 1 | zhangsan | 132****2889 | 25 | M | NoDesc | 2020-11-30 20:03:07 |
| 3 | lisi | 152****7873 | 18 | F | None | 2020-11-30 20:08:33 |
| 5 | wangwu | 136****2908 | 25 | M | Nothing | 2020-11-30 20:10:11 |
| 10 | zhaoliu | 138****5322 | 15 | M | Nothing | 2020-11-30 20:12:11 |
+----+----------+-------------+------+------+-------------+---------------------+
4 rows in set (0.00 sec)
mysql> update tb_person set name='looking', age=26, phone='152****9066' where id=10;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from tb_person;
+----+----------+-------------+------+------+-------------+---------------------+
| id | name | phone | age | sex | description | create_time |
+----+----------+-------------+------+------+-------------+---------------------+
| 1 | zhangsan | 132****2889 | 25 | M | NoDesc | 2020-11-30 20:03:07 |
| 3 | lisi | 152****7873 | 18 | F | None | 2020-11-30 20:08:33 |
| 5 | wangwu | 136****2908 | 25 | M | Nothing | 2020-11-30 20:10:11 |
| 10 | looking | 152****9066 | 26 | M | Nothing | 2020-11-30 20:12:48 |
+----+----------+-------------+------+------+-------------+---------------------+
4 rows in set (0.01 sec)