A write is a decision about which rows change and which stay still. Name the columns you insert, preview the WHERE population before you update or delete, then read the table back so the stored result—not the hope—is what you trust.
INSERT adds rows; named columns keep the mapping stable
INSERT appends new records. List the destination columns so each value has a name, not a position. Here is_active is omitted, so the table default of 1 fills it. If someone later adds a column to products, this statement still means the same three facts.
SQL BROWSER RUNNER
Insert catalog rows with named columns
Add two products and let the default publication flag apply.
Edit the query, predict the rows it will return, then run it.
INSERT...SELECT copies a query result
You do not have to type every row. INSERT ... SELECT takes the rows a query produces and appends them. That is how a reviewed draft list becomes a catalog, or how yesterday's report becomes an archive. The WHERE on the SELECT is the filter that decides which drafts are ready.
SQL BROWSER RUNNER
Publish drafts that meet a price rule
Copy selected draft rows into the catalog in one statement.
Edit the query, predict the rows it will return, then run it.
Preview UPDATE and DELETE with the same WHERE
Before changing production rows, run a SELECT that uses the same predicate you plan to write. If the preview shows the wrong product, the update would have been wrong too. Treat “I meant that one row” as a claim you prove, not a feeling.
Edit the query, predict the rows it will return, then run it.
UPDATE changes existing rows
SET names the new values. WHERE names the population. After the write, select the whole table so you can see that product 1 moved to 1299 cents and the others did not. Verification is cheaper than an incident.
SQL BROWSER RUNNER
Change one product price
Update a single product, then read every row to confirm the blast radius.
Edit the query, predict the rows it will return, then run it.
Constraints still reject bad writes
Inserts and updates are not exempt from the last lesson's rules. A negative price should fail CHECK (price_cents >= 0). Do not turn the rule off. Change the value, or change the schema if the rule itself is wrong.
SQL BROWSER RUNNER
Predict a rejected price change
Start from a valid product, then attempt an illegal write in the editor.
Edit the query, predict the rows it will return, then run it.
DELETE removes rows; target them narrowly
Physical delete forgets. Use it when the row should not exist—duplicate imports, true mistakes, data you are not allowed to keep. Combine identifiers and status so a published product cannot vanish because of a copied product_id alone. Preview first, then delete, then select what remains.
SQL BROWSER RUNNER
Delete one inactive product
Remove a specific retired row and confirm the others remain.
Edit the query, predict the rows it will return, then run it.
A status change keeps history
If orders, reports, or support tickets still refer to a product, deleting the row creates orphans or broken history. Setting is_active = 0 hides it from the live catalog while leaving the fact in place. That is a soft delete. Choose it when the record still has meaning.
SQL BROWSER RUNNER
Retire a product without removing it
Mark one product inactive and keep the row for later explanation.
Edit the query, predict the rows it will return, then run it.
A write checklist
State the one-row meaning of the table you are changing.
For INSERT, name columns and let defaults apply only when they are correct.
For UPDATE or DELETE, SELECT with the same WHERE and check the row count.
Run the write.
SELECT the result, including nearby rows that must not have changed.
If a constraint fails, treat it as information, not an obstacle to silence.
Independent lab: correct a lesson catalog
Start with two published lessons and a broken draft. The provided solution renames and publishes the draft as the views lesson, inserts a throwaway experiment, then deletes that experiment because it was never meant to ship. Read every statement before you run them, then confirm three published-quality rows remain.
SQL BROWSER RUNNER
Repair, publish, and clean a lesson list
Combine INSERT, a targeted UPDATE, and a narrow DELETE on a small catalog.
CREATETABLE lessons (
lesson_id INTEGERPRIMARYKEY,
title TEXTNOTNULL,statusTEXTNOTNULLCHECK(statusIN('draft','published','retired')),
duration_minutes INTEGERNOTNULLCHECK(duration_minutes >0));INSERTINTO lessons (lesson_id, title,status, duration_minutes)VALUES(1,'CREATE TABLE and schema design','published',155),(2,'Constraints and data integrity','published',155),(3,'Broken draft title','draft',40);UPDATE lessons
SET title ='Views and materialized views',status='published',
duration_minutes =155WHERE lesson_id =3ANDstatus='draft';INSERTINTO lessons (lesson_id, title,status, duration_minutes)VALUES(4,'Unused experiment','draft',20);DELETEFROM lessons
WHERE lesson_id =4ANDstatus='draft';SELECT lesson_id, title,status, duration_minutes
FROM lessons
ORDERBY lesson_id;
QUERY OUTPUT
Edit the query, predict the rows it will return, then run it.
Common mistakes to avoid
Inserting by column position so a later schema change maps values to the wrong fields.
Updating or deleting without a preview SELECT.
Omitting WHERE and rewriting the whole table.
Deleting a row that other tables or reports still need to explain.
Swallowing a constraint error and storing the bad value another way.
Trusting the write succeeded without reading the stored rows.
Lesson review
I can INSERT with named columns and intentional defaults.
I can copy a filtered result with INSERT ... SELECT.
I can preview an UPDATE or DELETE with the same WHERE.
I can explain why a missing WHERE is a table-wide write.
I can choose physical delete versus a status change.
I can verify a write by reading the table afterward.
KNOWLEDGE CHECK
Check your write-path reasoning
Answer all ten questions, then revisit the example whose WHERE clause or preview step still feels unclear.