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
- UPDATE modifies existing records in a table
- Always include a WHERE clause unless updating all rows
- Preview with SELECT before running UPDATE
- You can update multiple columns at once
- Use expressions and subqueries for complex updates