CodeBlanks Logo Icon CodeBlanks

UPDATE basics

Update rows with UPDATE.

UPDATE basics

With UPDATE you change rows in a table. SET gives the new value; WHERE picks which rows.

UPDATE products
SET price = 10
WHERE id = 1;

This query sets the price of product 1 to 10.

In products, price = 10 is updated. Only the rows where id = 1 holds are affected.

UPDATE basics — details

Without WHERE, UPDATE changes every row; always give a condition. After SET you write column = value.

Practice UPDATE basics

Set price to 10 for id=1 in products.

Starter code

query.sql
-- update price
UPDATE products
SET
WHERE id = 1

Sample solution

query.sql
UPDATE products
SET price = 10
WHERE id = 1

Expected output

1 satır güncellendi

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 What happens if WHERE is missing in UPDATE?

  • The first row
  • Raises an error
  • Only the name
  • All rows are updated Correct answer

Explanation: UPDATE without WHERE updates every row.

2 New value

Question
UPDATE products
____ price = 10
WHERE id = 1;
Answer
UPDATE products
SET price = 10
WHERE id = 1;

Explanation: UPDATE products SET price = 10 changes the price; WHERE id = 1 picks only that row.

3 UPDATE basics: match the terms

Term Meaning
UPDATE update
SET new value
WHERE condition
INSERT insert

All lessons in Beginner