When a book is destroyed or a reader withdraws from the Library, the scribe removes the matching row with the DELETE FROM command.
1DELETE FROM czytelnicy
2WHERE id = 12;Two parts:
Notice that with
DELETE we do not provide any columns - we remove the whole row, not a single field. (To clear just one field, we use UPDATE ... SET field = NULL.)WHERE may point to more than one row:1DELETE FROM ksiazki
2WHERE dostepna = 0;This will remove all books marked as unavailable.
This command looks harmless, yet it is the most dangerous of them all:
1DELETE FROM czytelnicy;Without
WHERE it removes ALL readers - the whole shelf is emptied! There is no trash bin, no undo. The scrolls are gone.That is why an experienced scribe has an iron habit: write WHERE first, only then the rest of the command. Some even check the condition with
SELECT * FROM table WHERE ... ended with a ";" to see which rows will disappear before they issue the DELETE.