MySQL 8 Cookbook
上QQ阅读APP看书,第一时间看更新

Updating

The UPDATE statement is used to modify the existing records in a table:

mysql> UPDATE customers SET first_name='Rajiv', country='UK' WHERE id=4;
Query OK, 1 row affected (0.00 sec)
Rows matched: 1
Changed: 1 Warnings: 0

WHERE: This is the clause used for filtering. Whatever condition(s) are issued after the WHERE clause are evaluated and the filtered rows are updated.

The WHERE clause is mandatory. Failing to give it will UPDATE the whole table.
It is recommended to do data modification in a transaction, so that you can easily rollback the changes if you find anything wrong. You can refer to  Chapter 5, Transactions to learn more about transactions.