We use cookies to enhance your experience on the site
CodeWorlds

The Scriptorium - UPDATE and DELETE

Knowledge is alive, so data must be corrected and sometimes deleted. In the Scriptorium scribes corrected scrolls - we do it with the

UPDATE
and
DELETE
statements.

UPDATE - changing values

UPDATE
changes existing rows. After
SET
we give the new values, and
WHERE
points to which rows to correct:

1UPDATE ksiazki SET cena = 19.99 WHERE id = 5;

DELETE - removing rows

DELETE
removes rows that meet a condition:

1DELETE FROM ksiazki WHERE id = 7;

The golden rule: always WHERE!

This is the scribe's most important warning. If you forget the

WHERE
clause:

1UPDATE ksiazki SET cena = 0;   -- changes the price of ALL books!
2DELETE FROM ksiazki;           -- removes ALL books!

Without

WHERE
the statement affects the whole shelf. This is one of the most dangerous mistakes when working with a database. Before you run
UPDATE
or
DELETE
, make sure you have added a condition pointing to the right rows. Caution is the mark of a master!

Go to CodeWorlds