CodeBlanks Logo Icon CodeBlanks

Updating data

Write the query to update a record with UPDATE.

Updating data

With UPDATE we change an existing record. SET gives the new value, WHERE picks which row to update.

UPDATE notes
SET title = 'Market listesi'
WHERE id = 3;

This updates the title of the note with id=3.

In notes, title = 'Market listesi' is updated. Only the rows where id = 3 holds are affected.

Updating data — details

Update is the U in CRUD. Without WHERE, UPDATE changes every row; always include a condition.

Practice Updating data

Set the title of the row with id=3 in notes to 'Shopping list'.

Starter code

query.sql
-- update the note
UPDATE notes
SET
WHERE id = 3

Sample solution

query.sql
UPDATE notes
SET title = 'Market listesi'
WHERE id = 3

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 Updating data: match the terms

Term Meaning
UPDATE update
SET new value
WHERE condition
INSERT insert

2 What happens if you omit WHERE in UPDATE?

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

Explanation: UPDATE without WHERE updates every row.

3 New value

Question
UPDATE notes
____ title = 'Yeni'
WHERE id = 3;
Answer
UPDATE notes
SET title = 'Yeni'
WHERE id = 3;

Explanation: In UPDATE, SET says which column gets which value.

All lessons in Beginner