Lessons › SQL › Deep Dive: Database Admin & ETL
SQL lesson
UPDATE SET for correcting values in place
UPDATE SET overwrites existing values directly inside a table - no need to delete and re-add a row.
Try this lesson free →Example
Correcting Retail Product Values with UPDATE SET
UPDATE products
SET category = 'Electronics'
WHERE product_id = 'P2001'| product_id | brand | category | price | status |
|---|---|---|---|---|
| P2001 | NovaTech | Electronics | 199.99 | active |
| P2002 | GlowUp | Beauty | 34.5 | activee |
| P2003 | FitGear | Sprots | 89.0 | active |
| P2004 | HomeNest | Home | 149.95 | inactive |
| P2005 | NovaTech | Electronics | 0.0 | active |
Step by step
- Start with UPDATE and the table whose rows you want to change.
UPDATE products; - SET names the column and the value you want it to become. Without WHERE this updates every row.
UPDATE products SET category = 'Electronics'; - WHERE limits the update to rows that match your condition - usually what you want.
UPDATE products SET category = 'Electronics' WHERE product_id = 'P2001';
Practice
1. Write an UPDATE statement on the products table to set category to 'updated' where product_id equals NULL.
UPDATE products SET category = 'updated' WHERE product_id = NULL2. Write an UPDATE statement on the customers table to set email to 'updated' where customer_id equals 'C101'.
UPDATE customers SET email = 'updated' WHERE customer_id = 'C101'3. Write an UPDATE statement on the orders table to set customer_id to 'updated' where order_id equals NULL.
UPDATE orders SET customer_id = 'updated' WHERE order_id = NULL4. Write an UPDATE statement on the inventory table to set product_id to 'updated' where warehouse equals NULL.
UPDATE inventory SET product_id = 'updated' WHERE warehouse = NULL5. 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 →