SQL Tutorial – Lesson 11

SQL UPDATE Statement – Complete Beginner's Guide with Examples (2026-27)

The SQL UPDATE statement is a Data Manipulation Language (DML) command used to modify existing records in a database table. You can update one column, multiple columns, or even all rows — always using the WHERE clause to target only the rows you need. In this beginner-friendly guide you will learn the UPDATE syntax, see step-by-step examples with before/after result tables, understand how to update multiple columns at once, and learn the critical safety rules to avoid updating the wrong rows.



✅ What is SQL UPDATE?

The SQL UPDATE statement is used to change the values of one or more columns in existing rows of a table. It is one of the four core DML (Data Manipulation Language) operations in SQL alongside SELECT, INSERT, and DELETE.

UPDATE modifies existing rows — it does NOT add new rows (that is INSERT) or remove rows (that is DELETE).

✅ The WHERE clause controls which rows are updated. Without it, ALL rows in the table are updated.

ℹ️ Real-world use cases: Give an employee a raise, change a customer's address, mark an order as shipped, correct a data entry mistake, or update the status of all items in a category.

✅ SQL UPDATE Syntax

Basic Syntax:-

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

UPDATE:- Specifies the table you want to modify.

SET:- Lists the columns and their new values, separated by commas.

WHERE:- Filters which rows to update. Without WHERE, ALL rows are updated.

⚠️ Golden Rule: ALWAYS include a WHERE clause in your UPDATE statement. Before running UPDATE, test your WHERE condition first with a SELECT statement to see exactly which rows will be affected.

✅ SQL UPDATE – Quick Reference Table

ScenarioSyntaxNotes
Update one columnUPDATE t SET col1 = v1 WHERE conditionOnly col1 is changed; other columns untouched
Update multiple columnsUPDATE t SET col1 = v1, col2 = v2 WHERE conditionSeparate pairs with a comma
Update all rowsUPDATE t SET col1 = v1⚠️ Dangerous — no WHERE means ALL rows change
Update with ANDUPDATE t SET col1 = v1 WHERE c1 = x AND c2 = yTargets rows matching both conditions
Update using calculationUPDATE t SET Salary = Salary + 1000 WHERE Dept = 'IT'Add/multiply/subtract from existing value

🔸 Starting Employees Table (used in all examples below)

Employees – Before UPDATE
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT9000Pune
3RAJSALES5000Delhi
4SUJANHR8000Pune
5MEENASALES12000Mumbai

✅ Example 1 – Update One Column

Update POOJA's salary from 9000 to 11000:

UPDATE Query
UPDATE Employees
SET Salary = 11000
WHERE Name = 'POOJA';

Result Show:-

Employees – After UPDATE
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT11000 ✅Pune
3RAJSALES5000Delhi
4SUJANHR8000Pune
5MEENASALES12000Mumbai
💡 Tip: Only POOJA's row was changed. All other rows stayed exactly the same because the WHERE clause targeted only Name = 'POOJA'.

✅ Example 2 – Update Multiple Columns at Once

Update SUJAN's salary AND city at the same time:

UPDATE Query
UPDATE Employees
SET Salary = 9500, City = 'Bangalore'
WHERE ID = 4;

Result Show:-

Employees – After UPDATE
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT11000Pune
3RAJSALES5000Delhi
4SUJANHR9500 ✅Bangalore ✅
5MEENASALES12000Mumbai
💡 Best Practice: Always separate multiple column updates with a comma inside the SET clause. Using ID = 4 as the WHERE condition is the safest option — it targets exactly one unique row.

✅ Example 3 – Update All Rows in a Department

Give every SALES employee a 1000 salary increase:

UPDATE Query
UPDATE Employees
SET Salary = Salary + 1000
WHERE Department = 'SALES';

Result Show:-

Employees – After UPDATE
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT11000Pune
3RAJSALES6000 ✅Delhi
4SUJANHR9500Bangalore
5MEENASALES13000 ✅Mumbai

Both RAJ (5000 → 6000) and MEENA (12000 → 13000) were updated because both are in SALES department.


✅ Example 4 – UPDATE with AND Condition

Update department to 'IT' only for employees in Pune with salary above 8000:

UPDATE Query
UPDATE Employees
SET Department = 'IT'
WHERE City = 'Pune' AND Salary > 8000;

Result Show:-

Employees – After UPDATE
IDNameDepartmentSalaryCity
1ANNIIT10000Mumbai
2POOJAIT ✅11000Pune
3RAJSALES6000Delhi
4SUJANHR9500Bangalore
5MEENASALES13000Mumbai
ℹ️ Note: Only POOJA matched BOTH conditions (City = 'Pune' AND Salary > 8000). SUJAN is in Bangalore, not Pune — so SUJAN was not updated. RAJ's salary is too low. AND requires ALL conditions to be true.

✅ Example 5 – ⚠️ Dangerous: UPDATE Without WHERE

This example shows what happens when you forget the WHERE clause:

⚠️ DANGEROUS Query – DO NOT run without WHERE
-- THIS UPDATES EVERY SINGLE ROW IN THE TABLE!
UPDATE Employees
SET Department = 'IT';

Result Show (ALL rows changed – disaster!):-

Employees – After UPDATE (No WHERE)
IDNameDepartmentSalaryCity
1ANNIIT ⚠️10000Mumbai
2POOJAIT ⚠️11000Pune
3RAJIT ⚠️6000Delhi
4SUJANIT ⚠️9500Bangalore
5MEENAIT ⚠️13000Mumbai
❌ DANGER: Every row was changed to IT — including RAJ (SALES) and SUJAN (HR)!
Without a WHERE clause, UPDATE affects ALL rows. Always run a SELECT with the same WHERE condition first to preview which rows will be changed before running the UPDATE.
✅ Safe approach – always SELECT first
-- Step 1: Preview which rows will be affected
SELECT * FROM Employees WHERE Department = 'SALES';

-- Step 2: Only THEN run the UPDATE
UPDATE Employees
SET Salary = Salary + 1000
WHERE Department = 'SALES';

✅ Key Points to Remember

  • Always use WHERE — without it, every row in the table is updated.
  • Test with SELECT first — run SELECT * FROM table WHERE your_condition before UPDATE to preview affected rows.
  • Update multiple columns by separating them with a comma in SET: SET col1 = v1, col2 = v2.
  • Use calculations in SETSET Salary = Salary + 1000 adds 1000 to the current value.
  • Use AND / OR to combine multiple conditions in WHERE for precise targeting.
  • Columns not listed in SET stay unchanged — UPDATE only modifies the columns you specify.
  • Use ID in WHERE when possibleWHERE ID = 4 targets exactly one unique row, the safest option.

✅ Common SQL UPDATE Mistakes to Avoid

❌ Mistake 1: Running UPDATE without WHERE
UPDATE Employees SET Salary = 5000; — updates ALL rows. Always add a WHERE condition. This mistake has caused many real production data disasters.
❌ Mistake 2: Forgetting single quotes around text values
Wrong: SET Department = IT — causes a syntax error.
Correct: SET Department = 'IT' — text values must be in single quotes.
❌ Mistake 3: Updating the wrong column
SET Name = 'POOJA' WHERE ID = 2 vs SET Salary = 11000 WHERE ID = 2 — always double-check column names before running UPDATE. A typo in the column name causes an error; a correct column with wrong value causes silent data corruption.
❌ Mistake 4: Using = NULL instead of IS NULL in WHERE
Wrong: WHERE City = NULL — always returns 0 rows.
Correct: WHERE City IS NULL
❌ Mistake 5: Missing comma between SET columns
Wrong: SET Salary = 11000 City = 'Mumbai' — syntax error.
Correct: SET Salary = 11000, City = 'Mumbai' — always separate column updates with a comma.

✅ Frequently Asked Questions (FAQ)

What does SQL UPDATE do?
The SQL UPDATE statement modifies existing records in a database table. You can update one column or multiple columns in one or more rows. It does NOT add new rows (that is INSERT INTO) or remove rows (that is DELETE). Use WHERE to target only the specific rows you want to change.
What happens if I run UPDATE without a WHERE clause?
If you omit the WHERE clause, ALL rows in the table will be updated with the new values. This is extremely dangerous in a production database. Always add a WHERE condition and test it with SELECT first to confirm which rows will be affected before running UPDATE.
Can I update multiple columns in one SQL UPDATE statement?
Yes. List all column = value pairs separated by commas inside the SET clause. For example: UPDATE Employees SET Salary = 12000, City = 'Mumbai' WHERE ID = 1; — this updates both Salary and City for employee with ID 1 in a single statement.
What is the difference between UPDATE and INSERT in SQL?
INSERT INTO adds a brand new row to the table — the row did not exist before. UPDATE modifies values in rows that already exist in the table. Use INSERT when adding new data, and UPDATE when changing existing data.
How do I safely test an UPDATE before running it?
Run SELECT with the same WHERE condition first: SELECT * FROM Employees WHERE Department = 'SALES'; — this shows you exactly which rows will be affected. Only after confirming those are the right rows, run the UPDATE with the same WHERE clause.
Can I use UPDATE with multiple conditions?
Yes. Combine conditions using AND and OR operators in the WHERE clause. Example: UPDATE Employees SET Salary = 15000 WHERE Department = 'IT' AND City = 'Pune'; — this updates only IT employees who are also in Pune. Both conditions must be true when using AND.


✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.