UPDATE Statements

Below is a sample SQL UPDATE command. This command is used to update one or more records in a database table.

UPDATE products 
SET price=34.55 
WHERE product_id=3

This first example is updating only one column. If we want to update more than one column we would separate the pairs of columns and their new values with commas.

UPDATE products 
SET product_price=44.55, 
product_name='Lamp' 
WHERE product=3

Note

  1. Without the WHERE clause, every record in the table would be effected and they would all end up with the same email address.
  2. There is no UNDO command on a database.
  3. The best WHERE clause is one that filters things based on a primary key, like user_id
  4. You can update multiple column values by listing each column and value pair separated by commas.