
📎 This article includes 2 downloadable practice files ↓
In this article
Reading data can’t hurt anything. Changing it can: one UPDATE without WHERE rewrites every row in the table. This lesson teaches the commands and, more importantly, the habits that keep you safe.
INSERT: add rows
INSERT INTO products (name, category, price, gst_rate)
VALUES ('Webcam', 'Peripherals', 1899, 0.18);
List the columns explicitly. The id column fills itself (INTEGER PRIMARY KEY in SQLite; IDENTITY or SERIAL elsewhere). Several rows: VALUES (...), (...), (...).
UPDATE: change rows
UPDATE products SET price = ROUND(price * 1.05, 2) WHERE category = 'Stationery';
UPDATE orders SET status = 'Delivered' WHERE status = 'Shipped';
DELETE: remove rows
DELETE FROM orders WHERE status = 'Cancelled';
The safety routine
- Write the WHERE as a SELECT first:
SELECT * FROM orders WHERE status = 'Cancelled';Check the rows and the count. - Change SELECT * to UPDATE/DELETE, keeping the exact same WHERE.
- Run it inside a transaction:
BEGIN;
DELETE FROM orders WHERE status = 'Cancelled';
SELECT COUNT(*) FROM orders; -- check
ROLLBACK; -- undo (or COMMIT; to keep)
Until COMMIT, nothing is permanent. DB Browser for SQLite also holds changes until you click Write Changes (Ctrl+S); Revert Changes undoes them.
Constraints protect you
NOT NULL, UNIQUE, CHECK (price >= 0) and FOREIGN KEY rules make the database refuse bad changes, like an order for a product that doesn’t exist. (In SQLite, run PRAGMA foreign_keys = ON; to enforce foreign keys.)
Where beginners go wrong
| Disaster | Prevention |
|---|---|
| UPDATE without WHERE: every row changed | SELECT first; transaction; some tools warn |
| Deleting customers who still have orders | Foreign keys; check with a JOIN first |
| No backup | Copy the file / take a backup before bulk changes |
| Running on the live system “just to test” | Use a test copy |
Practice
Download shop.db and this lesson’s exercise file below. Open the database in the free DB Browser for SQLite (or sqlite3 shop.db), paste the exercises into the Execute SQL tab and write a query for each task. The expected result is printed under every task; answers are at the bottom of the file.
📎 Practice files for this article
- 📄Practice database (SQLite)shop.db: 12 customers, 10 products and 300 orders (April-September 2026).⬇ DB · 28 KB
- 🗃️Lesson 10 exercisesTasks with the expected result under each, and answers at the bottom.⬇ SQL · 2 KB
Free to use for learning. Files with macros (.bas) are plain text — import them with Alt+F11 → File → Import File, and always test on a copy.
Stuck on a step? Ask a question and the AI answers using this article.