UPDATE
UPDATE changes existing rows. One missing WHERE clause can change every row in a table — so this lesson focuses on doing it safely.
On this page · 5 min · Beginner
On this page
- In simple words
- Learning objectives
- Explanation
- Syntax
- Code example
- Step by step
- Real-world use
- Common mistakes
- Best practices
- Remember this
- Practice exercise
- Mini quiz
- Related topics
- My notes
- Reading time
- 5 min
- Difficulty
- Beginner
- Updated
- Oct 27, 2026
Related tutorials
In simple words#
UPDATE is correcting entries with an eraser. Always say which rows (WHERE) — or you correct every entry in the register.
- UPDATE … SET
- Change column values.
- WHERE
- Limits which rows change — never forget it.
- @@ROWCOUNT
- How many rows were changed.
Learning objectives#
- Update specific rows with WHERE
- Set values from expressions
- Update using data from another table
- Review changes with OUTPUT and transactions
Explanation#
UPDATE Table SET Column = value WHERE condition changes matching rows. Without WHERE, every row is updated.
SET can use expressions such as Price = Price * 1.10.
OUTPUT deleted.Column shows the old value and inserted.Column the new value — perfect for checking what changed.
Run risky updates inside BEGIN TRAN so you can ROLLBACK if the row count is not what you expected.
Syntax#
UPDATE Table
SET col = expression
OUTPUT deleted.col, inserted.col
WHERE condition;
Code example: A 10% price rise on stationery#
UPDATE Products
SET Price = Price * 1.10
OUTPUT deleted.Name, deleted.Price AS OldPrice, inserted.Price AS NewPrice
WHERE Category = 'Stationery';
Name OldPrice NewPrice Pen 20.00 22.00 Notebook 60.00 66.00
This example is illustrative. Copy or download it and run it in your own environment; the expected output is shown above.
Step-by-step explanation#
- WHERE limits the change to the two Stationery products.
- Price * 1.10 is calculated for each row.
- deleted holds the row before the change; inserted holds it after.
Real-world use case#
Applying a seasonal price change or marking orders as shipped are typical UPDATE operations in back-office tools.
Common mistakes#
UPDATE Products SET Price = 0 sets every price to zero. Write the WHERE first, or test with a SELECT using the same condition.
If the joined table has several matching rows, the value applied is unpredictable. Make the join unique.
Best practices#
- Write and test the WHERE as a SELECT first
- Use BEGIN TRAN for manual updates and check @@ROWCOUNT
- Use OUTPUT to audit changes
- Update in batches for very large tables
Remember this#
UPDATE without WHERE changes every row.
Run the SELECT with the same WHERE first.
Use a transaction for important updates.
Practice exercise#
Your task: Mark order 103 as Delivered and show its old and new status.
Show solution
UPDATE Orders SET Status = 'Delivered' OUTPUT deleted.Status AS OldStatus, inserted.Status AS NewStatus WHERE OrderId = 103;
Mini quiz#
An UPDATE without WHERE changes only the first row.
Want more? Practise all SQL Server MCQs · SQL Server interview questions
My notes#
Saved in this browser.