The Three Statements

INSERT adds rows. UPDATE changes them. DELETE removes them.

Name your columns in an INSERT. Relying on column order works until someone adds a column, at which point every insert in the codebase silently writes to the wrong place.

Try it

Write an UPDATE that sets copies to 10 for that book, then a SELECT to confirm it. Two statements, separated by semicolons.

loading editor…
real SQLite, in your browser

The database is rebuilt from the fixture on every run, so you can experiment freely and press Run again to get a clean table back.

✦ UPDATE and DELETE without WHERE change every row

There is no confirmation and no undo. The habit that prevents it is simple and universal among people who have done this a while: write the WHERE as a SELECT first, look at exactly which rows come back, and only then change the SELECT into an UPDATE or a DELETE.

◈ Graded Query

Every book published before 1960 should have its copies set to 30. Write the UPDATE. Change only those books and leave every other row exactly as it was.

Checked against the rows your query returns. 2 visible and 3 hidden checks, some against data you cannot see.

loading editor…

Mark this lesson complete

Signed in, your progress follows you to every device.

Next: Transactions →
← Back