Deleting data
1. Delete data

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 table you're deleting from. The database removes all rows for which the WHERE condition is true. The WHERE condition 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';