Code of the Day
BeginnerQuerying basics

Changing data

Add, modify, and remove rows with INSERT, UPDATE, and DELETE.

SQLBeginner8 min read
Recommended first
By the end of this lesson you will be able to:
  • Add rows with INSERT
  • Modify rows with UPDATE, scoped by WHERE
  • Remove rows with DELETE, scoped by WHERE

So far you've only read data. Three statements change it. (Each Run below starts from a fresh copy of the shop inside a , so experiment freely — you can't break anything.)

INSERT

Add a row by listing the values:

SQL — editable, runs in your browser

The new customer appears at the end. (Running setup + your statements + a SELECT in one go is just for the demo — normally you'd run the INSERT on its own.)

UPDATE — mind the WHERE

UPDATE changes existing rows. The WHERE decides which rows:

SQL — editable, runs in your browser

An UPDATE or DELETE without a WHERE changes every row. UPDATE products SET price = 0; zeroes all prices. Always write (and double-check) the WHERE first — this is one of the most common, most painful SQL mistakes.

DELETE

DELETE removes rows matching the WHERE:

SQL — editable, runs in your browser

Edsger (NL) is gone. Same warning applies: no WHERE means delete everything.

Where to go next

That completes the reading and writing basics. Next up — the module lab, where you'll write graded queries against the shop.

Finished reading? Mark it complete to track your progress.

On this page