E-Learning Platform
0 of 139 builtAlways freeSign in
← Database Foundations I
3.01

Changing the Data

On this stop
  • INSERT, UPDATE, DELETE
  • Careful writes

For two units you've been reading. Every query so far — every SELECT, every JOIN — left the drawers exactly as it found them. You could run a thousand queries a day and the library wouldn't notice. That era ends now: this unit is about changing the facts, and it opens with the three statements that do it — and with why this unit is called The Vault.

The three writes

INSERT adds a new card to a drawer:

Up closeSQL
INSERT INTO members (name, joined)
VALUES ('Tefera Bekele', '2026-08-24');

Name the table, name the columns, supply the values, in matching order. The database fills in the id itself — it hands out card numbers, as promised back in Unit 1, so no two humans ever mint the same one.

UPDATE corrects cards that already exist:

Up closeSQL
UPDATE members
SET name = 'Marcus Lee-Okafor'
WHERE id = 2;

SET names the new value; WHERE says which cards — here, exactly one, picked out by primary key, the one label that never lies.

DELETE removes cards:

Up closeSQL
DELETE FROM loans
WHERE id = 41;

No SET, no SELECT — the card is gone from the drawer.

Three statements, and notice the family resemblance to everything you know: tables and columns by name, WHERE doing precisely what WHERE has always done. The grammar is old; only the stakes are new.

Writing is different in kind

Here's the shift to make in your head. A bad SELECT costs you a wrong tray — run it again, no harm done. A bad write changes the world, and the world doesn't have an undo key. This is the moment the librarian stops fetching and picks up a pen, and every library rule you'll meet in this unit exists because of pens.

Which brings us to the most famous mistake in databases. Look hard:

Up closeSQL
UPDATE members
SET name = 'Marcus Lee-Okafor';

No WHERE. And UPDATE without WHERE means what it says: every card in the drawer. Every member of the library is now named Marcus Lee-Okafor. DELETE without WHERE is the same story with a shredder. This isn't a beginner's error, either — seasoned professionals have hit Enter half a second before the feeling arrived. The pros' habit, worth adopting on day one: write the WHERE first, and when it matters, rehearse — run SELECT ... WHERE <the same condition> to see exactly which cards you're about to touch, count them, then swap in the UPDATE or DELETE. Measure twice, write once.

The right amount of fear

The goal of this lesson isn't to make you afraid of writes — libraries exist to be updated; a database nobody may change is a museum. The goal is respect: reads are questions, writes are commitments. And you're not alone with that pen, either. The rest of this unit is the library's own safety net — rules that refuse bad cards at the door, transactions that make half-finished changes impossible, backups for the truly bad day, and keys that decide who holds a pen at all.

First up: the rules at the door.