UPDATE Data
The UPDATE statement is used to modify existing data in a table. This chapter introduces various uses of the UPDATE statement.
Basic Syntax
Update Single Row
Update Multiple Columns
Update Multiple Rows
Update with Calculations
Update with Subquery
Update with JOIN
Update with CASE
Practical Examples
Update User Profile
Batch Status Update
Common Errors
Error 1: Forgetting WHERE Clause
Error 2: Safe Update Mode
Best Practices
- Always use WHERE clause
- Test with SELECT first
- Use transactions for important updates
- Backup data before bulk updates
- Add updated_at timestamp
Performance Tips
Summary
- UPDATE ... SET: Modify data
- WHERE clause: Specify which rows to update
- Multiple columns: Update several columns at once
- Calculations: Use expressions in SET
- Subqueries and JOINs: Complex updates
Next Step: Learn DELETE Data