beginner

UPDATE Statement

6 min readLast updated: 2026-07-23

Overview

The UPDATE statement modifies existing column values in a database table based on filter conditions.

Learning Objectives

  • Modify table attributes using UPDATE ... SET.
  • Apply targeted row filters using WHERE.
  • Avoid catastrophic un-filtered table updates.

Detailed Concept Explanation

UPDATE modifies column values for existing rows matching a WHERE condition.

The Missing WHERE Danger

If you omit the WHERE clause in an UPDATE query, every single row in the table will be updated!


Code Examples

SQL

sql
-- Increase salary by 10% for employees in department 5
UPDATE employees
SET salary = salary * 1.10
WHERE department_id = 5;

-- Update multiple columns simultaneously
UPDATE users
SET 
  status = 'Active',
  last_login = CURRENT_TIMESTAMP
WHERE user_id = 1042;

Best Practices

  • Test with SELECT First: Always run SELECT * FROM table WHERE condition before executing an UPDATE to verify which rows will be affected!

Interview Perspective

Danger

Production Danger: Unbounded UPDATE

Omitting WHERE in UPDATE employees SET status = 'Terminated' will terminate every employee in the company database! Always test WHERE predicates using SELECT first or run within a transaction block (BEGIN TRANSACTION).


Summary

UPDATE ... SET modifies column values in existing rows. Always verify your WHERE filter first!