SQL Update

The UPDATE statement modifies existing records in a table. Always use WHERE to avoid updating all rows unintentionally.

On this page

SQL UPDATE Statement

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

Basic Syntax

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

Update a Single Record

Update the email of one specific customer:

UPDATE customers
SET email = 'newemail@example.com'
WHERE id = 1;

Update Multiple Columns

You can update more than one column at the same time:

UPDATE customers
SET country = 'Canada',
    status = 'active'
WHERE id = 5;

Update Using Expressions

You can use calculations in UPDATE statements.

UPDATE products
SET price = price * 1.10
WHERE category = 'Electronics';

Update with NULL

If a column allows NULL, you can set it explicitly:

UPDATE customers
SET phone = NULL
WHERE id = 10;

IMPORTANT: UPDATE Without WHERE

If you omit the WHERE clause, ALL rows in the table will be updated.

-- WARNING: Updates every row
UPDATE customers
SET status = 'inactive';

Always double-check your WHERE condition before running an UPDATE statement.

Safe Update Practices

  • Always test your condition using SELECT first
  • Use transactions when updating critical data
  • Limit updates with primary keys whenever possible

Example: Test Before Update

-- Step 1: Test
SELECT id, status
FROM customers
WHERE country = 'USA';

-- Step 2: Update
UPDATE customers
SET status = 'inactive'
WHERE country = 'USA';

Next Step

Continue with SQL DELETE to learn how to safely remove records.