O'Reilly logo

Sams Teach Yourself MySQL by Chris Newman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required