BBampaa

Lessons › SQL › Deep Dive: Database Admin & ETL

SQL lesson

UPDATE SET

UPDATE SET overwrites existing values in a record without touching everything else.

Try this lesson free →
About 5–10 minutes · no sign-up needed

Example

Updating Existing Retail Product Values with UPDATE SET

UPDATE products
SET price = 22.99
WHERE product_id = 'P2004'

Result:

Step by step

  1. Start with UPDATE and the table whose rows you want to change.
    UPDATE products;
  2. SET names the column and the value you want it to become. Without WHERE this updates every row.
    UPDATE products
    SET price = 22.99;
  3. WHERE limits the update to rows that match your condition - usually what you want.
    UPDATE products
    SET price = 22.99
    WHERE product_id = 'P2004';

Practice

Try each one in your head first, then open the answer.

1. Write an UPDATE statement on the products table to set category to 'updated' where product_id equals 'P2001'.
UPDATE products SET category = 'updated' WHERE product_id = 'P2001'
2. Write an UPDATE statement on the customers table to set full_name to 'updated' where customer_id equals 'C101'.
UPDATE customers SET full_name = 'updated' WHERE customer_id = 'C101'
3. Write an UPDATE statement on the orders table to set order_id to 'updated' where customer_id equals 'C101'.
UPDATE orders SET order_id = 'updated' WHERE customer_id = 'C101'
4. Write an UPDATE statement on the inventory table to set warehouse to 'updated' where product_id equals 'P2001'.
UPDATE inventory SET warehouse = 'updated' WHERE product_id = 'P2001'
5. Write an UPDATE statement on the suppliers table to set supplier_name to 'updated' where supplier_id equals 'SUP001'.
UPDATE suppliers SET supplier_name = 'updated' WHERE supplier_id = 'SUP001'

Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.

Try this lesson free →
About 5–10 minutes · no sign-up needed