SQLMarrow / Course Academy Experience

SQL & Databases Masterclass Course

Welcome to the ultimate postgresql tutorial for beginners 2026. Work through interactive sql practice problems with solutions, master our comprehensive sql window functions tutorial modules, and prepare for tough sql interview questions at Google and Amazon entirely in your browser. Claim your course completion XP and build production-ready database mastery today!

COURSE PROGRESS
0%
0 of 40 Modules Solved
COURSE SYLLABUS
40 Lessons
LESSON WORKSPACEIntermediate

SQL Lesson 14: Updating rows

Introduction & Core Concept

When business data evolves (e.g., a customer changes their phone number or a product goes on sale), we modify active database rows using the UPDATE statement.

UPDATE table_name 
SET column1 = new_value, column2 = new_value 
WHERE condition;
CRITICAL WARNING: Always, without exception, include a WHERE constraint when writing an UPDATE statement. If you accidentally execute an UPDATE query without a WHERE filter, the database will instantly overwrite EVERY SINGLE ROW in the entire table with the new value!
Why & Where We Use It
  • Why We Use It: Allows systems to maintain accurate, up-to-date state tracking without deleting and recreating records from scratch.
  • Where We Use It: Updating order fulfillment statuses, adjusting product inventory stock levels, and saving edited user profile settings.
  • Real-World Example

    ShopMart decides to discount the price of their 'Quantum Pro Laptop' (Product ID: 101) by $100 and update its remaining warehouse stock count. They run an UPDATE query targeting strictly WHERE id = 101.

    Best Practices: What to Do & What NOT to Do
  • What to Do: Always run a SELECT query using your exact intended WHERE clause before executing your UPDATE. This lets you verify exactly which rows will be affected before committing the change.
  • What NOT to Do: Never run an UPDATE statement on a production database without wrapping it inside a transaction block (BEGIN TRANSACTION) so you can roll back errors safely.
  • Syntax & Pro Tips
    UPDATE products 
    SET price = 1199.99, stock = 12 
    WHERE id = 101;
    Interactive Sandboxed Terminal (Preloaded DB Schema: SHOPMART)
    SQL Query WorkspaceSQLite v3.45 (WASM Mode)
    QUICK INSERT:
    1