SQL UPDATE statement
SQL

SQL UPDATE statement — How to Modify Existing Data in a Table

CHAPTER 10 of 30 SQL Tutorial — Free Course on Neotech Navigators
The SQL UPDATE statement modifies existing data in a table. Unlike INSERT (which adds new rows), UPDATE changes values in rows that already exist. In this chapter, you will learn how to update single rows, multiple rows, multiple columns, and the critical importance of always using a WHERE clause with UPDATE.

The SQL UPDATE Statement

The UPDATE statement changes the values of one or more columns in existing rows. You learned to add new data with INSERT INTO in the previous chapter — now you will learn to modify it. Here is the basic syntax:

SQL — UPDATE Syntax
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
  • SET — specifies which columns to change and their new values
  • WHERE — filters which rows to update (without it, ALL rows are updated)

We will use this Employees table:

TABLE: Employees
+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 1  | Priya K.  | Sales      | 55000  | Mumbai    |
| 2  | John D.   | Marketing  | 62000  | London    |
| 3  | Arun M.   | IT         | 78000  | Delhi     |
| 4  | Emma W.   | Sales      | 51000  | Sydney    |
| 5  | Ravi S.   | IT         | 72000  | Mumbai    |
| 6  | Sara L.   | HR         | 58000  | New York  |
+----+-----------+------------+--------+-----------+

Update a Single Row

To update one specific row, use a WHERE clause that uniquely identifies it — typically by its primary key (ID):

SQL
UPDATE Employees
SET Salary = 60000
WHERE ID = 1;
✓ RESULT
+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 1  | Priya K.  | Sales      | 60000  | Mumbai    |
+----+-----------+------------+--------+-----------+
Priya's salary changed from 55000 to 60000.

Only the row where ID = 1 is affected. All other rows remain unchanged.

Update Multiple Columns at Once

You can change multiple columns in a single UPDATE statement by separating them with commas in the SET clause:

SQL
UPDATE Employees
SET Department = 'IT',
    City = 'Bangalore'
WHERE ID = 4;
✓ RESULT
+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 4  | Emma W.   | IT         | 51000  | Bangalore |
+----+-----------+------------+--------+-----------+
Emma moved from Sales/Sydney to IT/Bangalore.

Update Multiple Rows

When the WHERE clause matches more than one row, all matching rows are updated. You can combine conditions using AND, OR, NOT operators for precise targeting:

Give all IT employees a 10% raise:

SQL
UPDATE Employees
SET Salary = Salary * 1.10
WHERE Department = 'IT';
✓ RESULT — All IT Employees Updated
+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 3  | Arun M.   | IT         | 85800  | Delhi     |
| 5  | Ravi S.   | IT         | 79200  | Mumbai    |
+----+-----------+------------+--------+-----------+
Arun: 78000 → 85800 (+10%)
Ravi: 72000 → 79200 (+10%)

The expression Salary * 1.10 calculates a 10% increase based on the current salary for each row. SQL evaluates the expression row by row.

UPDATE Without WHERE — Danger Zone

⚠️ Critical Warning

Running UPDATE without a WHERE clause modifies every row in the table. This is almost always a mistake and can cause serious data loss. Always double-check your WHERE condition before running an UPDATE.

SQL — DANGEROUS: No WHERE Clause
-- ⚠️ This updates EVERY employee to Sales!
UPDATE Employees
SET Department = 'Sales';

Without WHERE, all 6 employees would be moved to Sales — destroying the original department data for IT, Marketing, and HR employees.

UPDATE with Calculations

You can use the current column value in your SET expression. SQL reads the old value and computes the new one:

Increase all salaries by 5000:

SQL
UPDATE Employees
SET Salary = Salary + 5000
WHERE City = 'Mumbai';
✓ RESULT
+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 1  | Priya K.  | Sales      | 60000  | Mumbai    |
| 5  | Ravi S.   | IT         | 77000  | Mumbai    |
+----+-----------+------------+--------+-----------+
Priya: 55000 → 60000 (+5000)
Ravi: 72000 → 77000 (+5000)

UPDATE with NULL Values

You can set a column to NULL to clear its value, or use IS NULL in the WHERE clause to update rows with missing data:

Clear Emma’s city:

SQL
UPDATE Employees
SET City = NULL
WHERE ID = 4;

Fill in missing departments:

SQL
UPDATE Employees
SET Department = 'General'
WHERE Department IS NULL;

This sets the department to “General” for any employee whose department is currently NULL.

Best Practices for SQL UPDATE

Practice Why It Matters
Always include a WHERE clause Prevents accidentally updating all rows
Test with SELECT first Run the same WHERE with SELECT to see which rows will be affected
Use primary key in WHERE Guarantees you update exactly one specific row
Back up before bulk updates Large updates can be hard to reverse without a backup
Update one table at a time Keeps changes focused and easier to verify

💡 Pro Tip: Test Before You Update

Before running an UPDATE, replace UPDATE ... SET with SELECT * using the same WHERE clause. This shows you exactly which rows will be affected without changing any data. Once you confirm the right rows are selected, switch back to UPDATE.

SQL — Test First, Then Update
-- Step 1: Test with SELECT
SELECT * FROM Employees
WHERE Department = 'IT' AND Salary < 75000;

-- Step 2: If the correct rows are returned, run the UPDATE
UPDATE Employees
SET Salary = Salary + 3000
WHERE Department = 'IT' AND Salary < 75000;

For a complete reference of the UPDATE syntax, see the official MySQL UPDATE documentation. In the next chapter, you will learn how to remove rows entirely with SQL DELETE.

If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.

📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.

🧪 Try It Yourself

Write two UPDATE statements:

  1. Change John D.’s department from Marketing to Sales
  2. Give all employees in Sales a salary increase of 2000
ANSWER — Query 1
UPDATE Employees
SET Department = 'Sales'
WHERE ID = 2;
ANSWER — Query 2
UPDATE Employees
SET Salary = Salary + 2000
WHERE Department = 'Sales';

To verify, run:

VERIFY
SELECT * FROM Employees
WHERE Department = 'Sales'
ORDER BY ID;

Expected Output:

+----+-----------+------------+--------+-----------+
| ID | Name      | Department | Salary | City      |
+----+-----------+------------+--------+-----------+
| 1  | Priya K.  | Sales      | 57000  | Mumbai    |
| 2  | John D.   | Sales      | 64000  | London    |
| 4  | Emma W.   | Sales      | 53000  | Sydney    |
+----+-----------+------------+--------+-----------+

📝 What You Learned in This Chapter

  • UPDATE modifies existing data in a table — it does not add or remove rows
  • Use SET to specify columns and their new values
  • Always include a WHERE clause to avoid updating all rows by accident
  • Update multiple columns by separating them with commas in SET
  • Use calculations in SET like Salary = Salary * 1.10 for percentage increases
  • Test with SELECT first to verify which rows will be affected
  • You can set columns to NULL or update rows where values are NULL

Frequently Asked Questions

What does the SQL UPDATE statement do?
The UPDATE statement modifies existing data in one or more rows of a table. It changes the values of specified columns for rows that match the WHERE condition. It does not add new rows (that is INSERT) or remove rows (that is DELETE).
What happens if I run UPDATE without WHERE?
Without a WHERE clause, UPDATE modifies every single row in the table. This is almost always unintentional and can cause major data loss. For example, UPDATE Employees SET Salary = 0 would set everyone’s salary to zero. Always include a WHERE clause unless you intentionally want to update all rows.
Can I update multiple columns in one query?
Yes. List all columns you want to change in the SET clause, separated by commas: UPDATE Employees SET Department = 'IT', City = 'Delhi', Salary = 75000 WHERE ID = 4. All specified columns are updated in a single operation for the matching rows.
Can I undo an UPDATE in SQL?
If the UPDATE was inside a transaction that has not been committed, you can use ROLLBACK to undo it. If the transaction was already committed (or auto-commit is on, which is the default in most systems), the change is permanent. This is why testing with SELECT first and making backups before large updates is critical.
How do I update a column using its current value?
Reference the column name on the right side of SET. For example, SET Salary = Salary + 5000 adds 5000 to the current salary, and SET Salary = Salary * 1.10 increases it by 10%. SQL reads the old value, performs the calculation, and writes the new value for each matching row.

📖 Chapter 10 of 30 — SQL Tutorial on Neotech Navigators

PK
Meet PK, the founder of NeotechNavigators.com! With over 15 years of experience in Data Visualization, Excel Automation, and dashboard creation. PK is a Microsoft Certified Professional who has a passion for all things in Excel. PK loves to explore new and innovative ways to use Excel and is always eager to share his knowledge with others. With an eye for detail and a commitment to excellence, PK has become a go-to expert in the world of Excel. Whether you're looking to create stunning visualizations or streamline your workflow with automation, PK has the skills and expertise to help you succeed. Join the many satisfied clients who have benefited from PK's services and see how he can take your data analysis skills to the next level!
https://neotechnavigators.com