Chapter 3. DELETE and UPDATE: A change will do you good

image with no caption

Keep changing your mind? Now it’s OK! With the commands you’re about to learn—DELETE and UPDATE—you’re no longer stuck with a decision you made six months ago, when you first inserted that data about mullets coming back into style soon. With UPDATE, you can change data, and DELETE lets you get rid of data that you don’t need anymore. But we’re not just giving you the tools; in this chapter, you’ll learn how to be selective with your new powers and avoid dumping data that you really do need.

Clowns are scary

Suppose we want to keep track of the clowns in Dataville. We could create a clown_info table to track them. And we could use a last_seen column to keep track of the clowns’ whereabouts.

image with no caption

Clown tracking

Here’s our table. We can leave out information we don’t know and fill it in later. Every time we have a new clown sighting, we can add a new row. We’ll have to change this table frequently to keep it up to date.

image with no caption

Get Head First SQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.