UPDATE Statement in SQL

11/22/2025
All Articles

SQL UPDATE statement tutorial for beginners

UPDATE Statement in SQL

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


πŸ”Ή 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

id name email city
1 Amit amit@example.com Delhi
2 Neha neha@example.com Mumbai
3 Rahul rahul@example.com 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.

Article