借助 UPDATE 语句和 WHERE 子句,我们可以更新表中单行或多行的值。 MySQL 根据 WHERE 子句中指定的条件更新值。例如,假设在“employee”表中我们想要更改 id 为 1 的员工的“name”和“doj”,那么可以使用以下查询来完成 -
mysql> UPDATE employee SET name = 'Gaurav', doj = '2010-02-01' WHERE id = 1;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select * from employee WHERE id = 1;
+------+--------+------------+
| id | name | doj |
+------+--------+------------+
| 1 | Gaurav | 2010-02-01 |
+------+--------+------------+
1 row in set (0.00 sec)