UPDATE 命令与 WHERE 子句一起可用于更改行实例的值。基本上,MySQL 会根据查询中给出的条件更改值。下面的例子可以演示它
假设我们想在下面给出的“testing”表中将名称从“Ram”更改为“Mohit” -
mysql> Select * from testing;
+----+---------+
| Id | Name |
+----+---------+
| 1 | Harshit |
| 2 | Lovkesh |
| 3 | Ram |
| 4 | Gaurav |
+----+---------+
4 rows in set (0.00 sec)
现在,通过运行以下查询,我们可以将 row 的实例更改为“Mohit”,其中它是“ram”。
mysql> UPDATE TESTING SET Name = 'MOHIT' WHERE name = ‘ram’;
Query OK, 1 row affected (0.13 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> Select * from testing;
+-----+---------+
| id1 | Name |
+-----+---------+
| 1 | Harshit |
| 2 | Lovkesh |
| 3 | MOHIT |
| 4 | Gaurav |
+-----+---------+
4 rows in set (0.00 sec)