Chapter Five · Changing Data Safely
Changing Data
For three chapters the Marquee's data has sat behind read-only glass: SELECT looks and changes nothing. This chapter hands you the three verbs that write — INSERT, UPDATE, and DELETE — which also means it hands you your first real chance to do damage. So the verbs come bundled with the habits that make them safe: the row counts professionals read, the SELECT they run first, and the most famous eight-character mistake in SQL, staged here in slow motion so it never has to happen to you at work.
The verbs themselves are small. INSERT adds rows, and the database's rules audition every new one at the door. UPDATE edits rows that are already there, in place. DELETE removes rows — except in the many real systems where rows are never truly removed at all, only marked cancelled, for reasons an accountant would recognize instantly. All three reuse the WHERE clause you have been writing since Chapter 3, and that reuse cuts both ways: you already know exactly how to aim these verbs, and a WHERE left off by accident aims them at everything.
Four topics carry the chapter. INSERT gives rows life and shows the constraint checks working in real time. UPDATE stages the missing-WHERE disaster deadpan, then teaches the reflex that prevents it. DELETE meets foreign keys pushing back and learns the industry's soft-delete habit. And the last topic opens the bulk doors: how the 800 customers in Lora's old spreadsheet move into the customers table in one command, and how any query becomes a file she can mail to her accountant.