Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Inserting data
Modifying data
Deleting data
12. Delete data
CRUD

Instruction

All right! Now you will learn how to delete data from the database. To delete data from a database, you use – surprise, surprise – the DELETE command.

To delete the user with ID 1, type:

DELETE FROM user 
WHERE id = 1; 

Here, user is the name of the table you're deleting from. The database removes all rows for which the WHERE condition is true. The WHERE condition in the DELETE FROM command can be the same as the WHERE condition in the SELECT command.

As with the UPDATE command, the database always tells you how many rows it has deleted.

Exercise

Oops, we've run out of sugar! Delete all desserts from our menu.

Stuck? Here's a hint!

Type:

DELETE FROM dish 
WHERE type = 'dessert';