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:
UPDATE table_name
SET column1 = value1, column2 = value2, ...
WHERE condition;
SET— specifies which columns to change and their new valuesWHERE— filters which rows to update (without it, ALL rows are updated)
We will use this Employees table:
+----+-----------+------------+--------+-----------+
| 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):
UPDATE Employees
SET Salary = 60000
WHERE ID = 1;
+----+-----------+------------+--------+-----------+ | 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:
UPDATE Employees
SET Department = 'IT',
City = 'Bangalore'
WHERE ID = 4;
+----+-----------+------------+--------+-----------+ | 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:
UPDATE Employees
SET Salary = Salary * 1.10
WHERE Department = 'IT';
+----+-----------+------------+--------+-----------+ | 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.
-- ⚠️ 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:
UPDATE Employees
SET Salary = Salary + 5000
WHERE City = 'Mumbai';
+----+-----------+------------+--------+-----------+ | 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:
UPDATE Employees
SET City = NULL
WHERE ID = 4;
Fill in missing departments:
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.
-- 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:
- Change John D.’s department from Marketing to Sales
- Give all employees in Sales a salary increase of 2000
UPDATE Employees
SET Department = 'Sales'
WHERE ID = 2;
UPDATE Employees
SET Salary = Salary + 2000
WHERE Department = 'Sales';
To verify, run:
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
UPDATEmodifies existing data in a table — it does not add or remove rows- Use
SETto 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.10for 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
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.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.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.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



