Lesson 18 Intermediate Level
18 of 30 lessons

UPDATE Statement

Learn how to modify existing data in tables using UPDATE statements with WHERE clause. The UPDATE statement is essential for maintaining data accuracy.

Introduction

The UPDATE statement is used to modify existing records in a table. You can update one or multiple columns using a WHERE clause to target specific rows.

Basic Syntax

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

Example: Update Salary

-- Increase salary of employee ID 101
UPDATE employees
SET salary = salary + 500
WHERE employee_id = 101;

Update Multiple Columns

UPDATE employees
SET salary = 7000,
    department_id = 60
WHERE employee_id = 102;

Update All Rows

Warning: If you omit the WHERE clause, all rows in the table will be updated.

-- Set all salaries to 5000
UPDATE employees
SET salary = 5000;

Best Practices

  • Always use WHERE to avoid updating unintended rows.
  • Test your update using a SELECT with the same condition first.
  • Use ROLLBACK before COMMIT if unsure.

Practice Task