Delete Data - DELETE¶
Now let's delete some data using DB Browser. It is great and terrible how easy it is to wipe out data in a database.
Delete with SQL¶
This Person
was a mistake on entry, so let's just delete it.
Let's see how to delete it with SQL:
DELETE
FROM users
WHERE last = "Person";
This means, more or less:
Hey SQL database 👋, I want to
DELETE
rowsFROM
the table calledusers
.Please delete all the rows
WHERE
the value of the columnlast
is equal to"Person"
.
Remember that when using a SELECT
statement it has the form:
SELECT [some stuff here]
FROM [name of a table here]
WHERE [some condition here]
DELETE
is very similar, and again we use FROM
to tell the table to work on, and we use WHERE
to tell the condition to use to match the rows that we want to delete.
You can try that in DB Browser for SQLite:
Have in mind that DELETE
is to delete entire rows, not single values in a row.
If you want to "delete" a single value in a column while keeping the row, you would instead update the row as explained in the previous chapter, setting the specific value of the column in that row to NULL
(to None
in Python).
id | first | last | username | |
---|---|---|---|---|
1 | colrc@gmail.com | Lawrence | Nicodemus | original |
2 | jdoe@gmail.com | John | Doe | jdoe |
3 | jadoe@gmail.com | Jane | Doe | jadoe |
null | rdoe@gmail.com | Robert | Doe | rdoe |
5 | nobody@gmail.com ✨ | New | Person | nperson |
Recap¶
Deleting rows is trivial. 🔥 Unless you run into constraint violations, which we will examine in the next tutorial.