Ira SQL ProIra SQL Pro

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

  1. Always Use WHERE — Without WHERE, every row in the table is updated. This is almost never what you want.
  2. Multiple Columns — Set multiple columns in a single UPDATE by separating assignments with commas.
  3. Expressions — You can use expressions: SET price = price * 1.1 increases price by 10%.
  4. RETURNING — Append RETURNING * to see the updated rows.
  5. Transactions — Wrap critical updates in a transaction so you can roll back if something goes wrong.
  6. FROM Clause — PostgreSQL allows UPDATE ... FROM to 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.

Related Topics