The UPDATE Statement

The UPDATE statement is used to change one or some of the values in a data row. As with DELETE, you include a WHERE clause to indicate that this row or rows are to be updated.

Updating

Without a WHERE clause, UPDATE performs the same update on every row in the table. Unless this is the result you want, always include a WHERE clause in an UPDATE statement.

You specify the values to be changed in a list after the SET keyword, separated with commas. The following example updates the name and price of an existing product:

mysql> UPDATE products
    -> SET name = 'Large product (new and improved)',
    ->     price = 23.99
    -> WHERE product_code ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.