UPDATE Statement

SQL FundamentalsDMLFree Lesson

Advertisement

The UPDATE Statement

The UPDATE statement modifies existing records in a table.

💡 UPDATE changes the values of one or more columns in existing rows. ALWAYS use a WHERE clause!

Basic Syntax

UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;

Update a Single Column

UPDATE employees
SET salary = 80000
WHERE first_name = 'Alice' AND last_name = 'Johnson';

Update Multiple Columns

UPDATE employees
SET
    salary = 85000,
    department = 'Senior Engineering'
WHERE id = 1;

Update with Expression

-- Give all Engineering employees a 10% raise
UPDATE employees
SET salary = salary * 1.10
WHERE department = 'Engineering';

Safe Update Pattern

-- Step 1: Preview affected rows
SELECT * FROM employees WHERE department = 'Engineering';

-- Step 2: Run the update
UPDATE employees SET salary = salary * 1.10 WHERE department = 'Engineering';

-- Step 3: Verify the changes
SELECT * FROM employees WHERE department = 'Engineering';

⚠️ Omitting the WHERE clause updates ALL rows. Always test with SELECT first!

✅ Key Takeaways

  1. UPDATE modifies existing records in a table
  2. Always include a WHERE clause unless updating all rows
  3. Preview with SELECT before running UPDATE
  4. You can update multiple columns at once
  5. Use expressions and subqueries for complex updates

Advertisement

Need Expert SQL Help?

Get personalized SQL training or database consulting.

Advertisement