UPDATE Statement in SQL

11/22/2025

SQL UPDATE statement tutorial for beginners

Go Back

UPDATE Statement in SQL – SQL Tutorial for Beginners

The UPDATE statement in SQL is used to modify existing records in a table. It is one of the essential operations in any database system, allowing you to change stored data safely and efficiently.

In this beginner-friendly SQL tutorial, you will learn:

  • What UPDATE does

  • UPDATE syntax

  • Updating single and multiple columns

  • Updating multiple rows

  • Using WHERE clause with UPDATE

  • Updating with conditions

  • Real-world examples

  • Best practices


SQL UPDATE statement tutorial for beginners

🔹 What Is the UPDATE Statement?

The UPDATE statement modifies existing rows in a table.

If you do not use WHERE, all rows in the table will be updated!


🔸 Basic Syntax of UPDATE

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

Example Table: users

idnameemailcity
1Amit[email protected]Delhi
2Neha[email protected]Mumbai
3Rahul[email protected]Bengaluru

🔸 Example 1: Update a Single Column

Change Neha's city:

UPDATE users
SET city = 'Pune'
WHERE id = 2;

🔸 Example 2: Update Multiple Columns

UPDATE users
SET name = 'Rahul Sharma', city = 'Hyderabad'
WHERE id = 3;

🔸 Example 3: Update Multiple Rows

Update city for all users living in Delhi:

UPDATE users
SET city = 'Noida'
WHERE city = 'Delhi';

🔸 Example 4: Update Without WHERE (⚠ Dangerous)

UPDATE users
SET city = 'Unknown';

This will update all rows in the table.


🔸 Example 5: Update Using Expressions

Increase salary by 10%:

UPDATE employees
SET salary = salary * 1.10;

🔸 Example 6: Update Using Another Column

Copy value from another field:

UPDATE products
SET final_price = base_price - discount;

🔸 Example 7: Update Using Subquery

Update product prices to match the latest prices:

UPDATE products p
SET p.price = (
  SELECT new_price
  FROM latest_prices lp
  WHERE lp.product_id = p.id
)
WHERE p.id IN (SELECT product_id FROM latest_prices);

🔹 Real-World Use Cases

✔ Update user profile information

UPDATE users
SET name = 'John', city = 'Chennai'
WHERE id = 10;

✔ Mark an order as shipped

UPDATE orders
SET status = 'Shipped'
WHERE order_id = 1023;

✔ Reduce stock after a purchase

UPDATE products
SET stock = stock - 1
WHERE id = 50;

🔹 Common Errors & Fixes

❗ Updating all rows by mistake

Missing WHERE clause → updates whole table.

Fix: Always double-check WHERE.

❗ Incorrect data type

UPDATE users SET age = 'abc'; -- wrong

Fix: Use correct types.

❗ Updating non-existing rows

Using wrong conditions results in 0 rows updated.


🔹 Best Practices

✔ Always use a WHERE clause (unless updating whole table intentionally)
✔ Use transactions for bulk updates
✔ Backup critical tables before major updates
✔ Test with SELECT before UPDATE
✔ Log changes for auditing
✔ Use LIMIT (MySQL) for safer updates


Summary

In this SQL UPDATE tutorial, you learned:

  • What UPDATE does

  • How to update single/multiple columns

  • How to update multiple rows

  • Real-world update scenarios

  • Best practices to avoid mistakes

UPDATE is essential for modifying data in any SQL-based application.