Updating data
- SQL course
- Beginner
- Lesson 22/115
- 5 min
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
-- update the note
UPDATE notes
SET
WHERE id = 3Sample solution
UPDATE notes
SET title = 'Market listesi'
WHERE id = 3Expected 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
UPDATE notes
____ title = 'Yeni'
WHERE id = 3;
UPDATE notes
SET title = 'Yeni'
WHERE id = 3;
Explanation: In UPDATE, SET says which column gets which value.