SQL UPDATE Statement
beginnerbasics
2 min read
What is the UPDATE Statement?
The UPDATE statement modifies existing rows in a table. You specify which columns to change and optionally a WHERE clause to target specific rows.
Syntax
UPDATE table_name
SET column1 = value1, column2 = value2
WHERE condition;When to Use
- Changing a user's email address
- Updating order statuses
- Correcting data entry errors
- Applying bulk changes based on a condition
Key Points
- Always Use WHERE — Without
WHERE, every row in the table is updated. This is almost never what you want. - Multiple Columns — Set multiple columns in a single
UPDATEby separating assignments with commas. - Expressions — You can use expressions:
SET price = price * 1.1increases price by 10%. - RETURNING — Append
RETURNING *to see the updated rows. - Transactions — Wrap critical updates in a transaction so you can roll back if something goes wrong.
- FROM Clause — PostgreSQL allows
UPDATE ... FROMto join another table during the update.
Guided Practice
Solve the challenge below. Use hints when stuck and check your answer for instant feedback.
Practice challengeGuided learning mode
SQL UPDATE Statement Challenge
Write a query that solve this task: change the grade for a specific student.
Expected result
One row updated. Student with id 3 now has grade A.
Hidden checks
- Returned rows and values
- Output columns and result shape
- Final database state after the query runs
Lesson guidance
What is the UPDATE Statement?
Initializing database...Each run starts from fresh sample data.
More Examples
Bulk price increase
Increase all product prices by 10 percent.
Initializing database...Each run starts from fresh sample data.
Frequently Asked Questions
What happens if I run UPDATE without WHERE?
Every row in the table will be updated. Always include a WHERE clause unless you intentionally want to update all rows.
Can I update a column using its current value?
Yes. For example, UPDATE products SET price = price + 5 WHERE id = 1; adds 5 to the current price.