Skip to content
/Chapter 8 · DML: Measure Twice, Cut Once
Lesson 8.3·garden_shop
Lesson 8.3

Updating Rows with SQL UPDATE

UPDATE changes rows in place. The WHERE clause decides which ones. Leave it off and you change them all.

UPDATE changes the values in rows that already exist. You can set several columns in one statement by separating them with commas.

The most important part of an UPDATE is the WHERE. Without it, the change applies to every row in the table. That is the classic accident this chapter is named after, so write the filter first, and confirm with a SELECT afterward.

Pattern
update products
set price = 19.99
where product_id = 4;

select product_id, price from products where product_id = 4;
Schema · Garden ShopTable · orders6 columns · 24 rows
Table · orders

One row per order. Unshipped orders have a null shipped_date.

6 columns · 24 rows
order_id intcustomer_id intorder_date dateshipped_date datestatus textcoupon_code text
Your task

Order 7 just shipped. Update it: set itsstatus to 'shipped' and itsshipped_date to 2024-06-20, touching only order 7. Then SELECTorder_id,status, and shipped_date for that order to confirm.

SQL Workbench
query.sqlgarden_shop · SQL engine loading
⌘↵ to run
·
Expected answer
  • Columns: order_id, status, shipped_date.
  • Rows: 1, order 7.
  • After the update, status is 'shipped' and shipped_date is 2024-06-20.