1、update ...set...where...
题目:修改students id=2的name为“yanxia”
mysql>update students set name ="yanxia" where id=2;
Query OK, 1 row affected (0.04 sec)
Rows matched: 1 Changed: 1 Warnings: 0
2、更新(修改)多个字段
mysql> select*from students;
+----+---------+-----+-----+-------------+
| id | name | sex | age | tel |
+----+---------+-----+-----+-------------+
| 1 | lili | f | 12 | 13501665963 |
| 2 | yanxia | m | 25 | 15101122005 |
| 3 | jujo | m | 21 | 15610055009 |
| 4 | jojo | f | 24 | 18701559960 |
| 5 | kaite | f | 20 | - |
| 6 | hathway | m | 21 | - |
| 7 | lili | f | 11 | 15110021003 |
| 8 | LiLi | f | 10 | 18710051006 |
+----+---------+-----+-----+-------------+
8 rows in set (0.00 sec)
mysql>update students set name="lili",name="jojo" where age<20;
Query OK, 3 rows affected (0.04 sec)
Rows matched: 3 Changed: 3 Warnings: 0
mysql> select*from students;
+----+---------+-----+-----+-------------+
| id | name | sex | age | tel |
+----+---------+-----+-----+-------------+
| 1 | jojo | f | 12 | 13501665963 |
| 2 | yanxia | m | 25 | 15101122005 |
| 3 | jujo | m | 21 | 15610055009 |
| 4 | jojo | f | 24 | 18701559960 |
| 5 | kaite | f | 20 | - |
| 6 | hathway | m | 21 | - |
| 7 | jojo | f | 11 | 15110021003 |
| 8 | jojo | f | 10 | 18710051006 |
+----+---------+-----+-----+-------------+
8 rows in set (0.00 sec)
3、设置age字段的值
mysql> select*from students;
+----+---------+-----+------+
| id | name | sex | age |
+----+---------+-----+------+
| 1 | kimi | f | 12 |
| 2 | hathway | m | NULL |
| 3 | tony | f | NULL |
+----+---------+-----+------+
3 rows in set (0.00 sec)
mysql> update students set age =15 where id >=2;
Query OK, 2 rows affected (0.01 sec)
Rows matched: 2 Changed: 2 Warnings: 0
mysql> select*from students;
+----+---------+-----+------+
| id | name | sex | age |
+----+---------+-----+------+
| 1 | kimi | f | 12 |
| 2 | hathway | m | 15 |
| 3 | tony | f | 15 |
+----+---------+-----+------+
3 rows in set (0.00 sec)