The UPDATE statement is used to modify existing rows in a table.
1.Basic Syntax
- table_name → The table to update
- SET → Columns and new values
- WHERE → Filters which rows to update (important!)
⚠ Without WHERE, all rows in the table will be updated.
2.Example Table
Employees Table
| EmployeeID | Name | Department | Salary |
|---|---|---|---|
| 1 | John | IT | 5000 |
| 2 | Jane | HR | 4500 |
| 3 | Mike | IT | 6000 |
3.Update a Single Column
Result: Jane’s salary is now 5500.
4.Update Multiple Columns
Result: Mike’s department and salary updated.
5.Update Multiple Rows
Result: All IT employees get a 500 salary increase.
6.Update Using Another Table
- Can update data based on another table
- Very useful for bulk updates or migrations
7.Update Using a Subquery
- Subquery defines which rows to update
8.Update With CASE Statement
- Allows conditional updates in a single statement
