CodeBlanks Logo Icon CodeBlanks

Deleting data

Write the query to delete a record with DELETE.

Deleting data

With DELETE we remove a record. WHERE picks which row to delete; without it all rows are deleted.

DELETE FROM notes
WHERE id = 3;

This deletes the note with id=3.

Rows are deleted from notes. Only the rows where id = 3 holds are affected.

Deleting data — details

Delete is the D in CRUD. After DELETE FROM comes the table name, then WHERE with a condition. Deleted data cannot be undone; be careful.

Practice Deleting data

Delete the row with id=3 from the notes table.

Starter code

query.sql
-- delete the note
DELETE FROM notes
WHERE

Sample solution

query.sql
DELETE FROM notes
WHERE id = 3

Expected output

1 satır silindi

Questions and answers

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

1 Delete row

Question
DELETE ____ notes
WHERE id = 3;
Answer
DELETE FROM notes
WHERE id = 3;

Explanation: Deleting rows uses DELETE FROM table WHERE condition.

2 What happens if WHERE is missing in DELETE?

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

Explanation: DELETE without WHERE deletes every row.

3 Deleting data: match the terms

Term Meaning
DELETE delete
FROM table
WHERE condition
UPDATE update

All lessons in Beginner