The UPDATE statement is used to modify existing rows in a table.

1.Basic Syntax

UPDATE table_name
SET column1 = value1,
    column2 = value2,
    ...
WHERE condition;
  • 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

UPDATE Employees
SET Salary = 5500
WHERE EmployeeID = 2;

Result: Jane’s salary is now 5500.

4.Update Multiple Columns

UPDATE Employees
SET Department = 'Finance', Salary = 6000
WHERE EmployeeID = 3;

Result: Mike’s department and salary updated.

5.Update Multiple Rows

UPDATE Employees
SET Salary = Salary + 500
WHERE Department = 'IT';

Result: All IT employees get a 500 salary increase.

6.Update Using Another Table

UPDATE e
SET e.Salary = s.NewSalary
FROM Employees e
INNER JOIN SalaryUpdates s
    ON e.EmployeeID = s.EmployeeID;
  • Can update data based on another table
  • Very useful for bulk updates or migrations

7.Update Using a Subquery

UPDATE Employees
SET Salary = Salary * 1.1
WHERE EmployeeID IN (SELECT EmployeeID FROM Employees WHERE Department = 'HR');
  • Subquery defines which rows to update

8.Update With CASE Statement

UPDATE Employees
SET Salary = CASE
                WHEN Department = 'IT' THEN Salary + 500
                WHEN Department = 'HR' THEN Salary + 300
                ELSE Salary
             END;
  • Allows conditional updates in a single statement

9.Update All Rows

UPDATE Employees
SET Salary = Salary + 100;

Categorized in:

SQL Server,