Performing Updates

With the UPDATE command, you can modify the values of existing data in a table. The format for the statement is as follows:

UPDATE [LOW PRIORITY] [IGNORE] table_name
  SET column_name1=expression1, column_name2=expression2,...
  [WHERE where_definition]
  [LIMIT num]

There are basically two parts to the query: the SET portion, to declare which column to set to what value; and the WHERE portion, which defines which rows are affected.

Let's practice using CREATE and INSERT again to create a temporary table called products and populate it with some data:

mysql> CREATE TEMPORARY TABLE products
    -> (product_name VARCHAR(20), price FLOAT(9,2));

mysql> INSERT INTO products
    -> VALUES ('Green sweater', 10.00),
    -> ('Brown jacket', 12.00); ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition 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.