Sometimes data in the Library must change: a book's price rises, a reader changes city, a book returns from a loan. For this we use UPDATE.
1UPDATE ksiazki
2SET cena = 59.90
3WHERE id = 5;The three parts of this command:
In a single
SET we can change several columns, separating them with commas:1UPDATE czytelnicy
2SET miasto = 'Aleksandria', email = 'hypatia@biblioteka.aleksandria'
3WHERE id = 7;Look at this command WITHOUT the
WHERE clause:1UPDATE ksiazki
2SET cena = 59.90;This will change the price of ALL books in the Library to 59.90! Every scroll gets the same price, and the original data is lost forever.
WHERE is the scribe's sight. Without it UPDATE strikes the entire shelf. Before you run an UPDATE, always ask yourself: which exact rows do I want to change? - and write the matching WHERE.