Level 5 · Databases and Data Management · Course 5.2 SQL
Module 57: Transactions and Indexes
Goal: keep data correct when several changes must happen together, or many people change data at once, using transactions; and make queries fast with indexes, checked with query plans.
You'll need: your crm.db and queries.sql from Module 56.
Lessons
- 1Transactions15–25 minutes✓
- 2ACID15–25 minutes✓
- 3Indexes15–25 minutes✓
- 4Reading query plans15–25 minutes✓
- 5Performance habits15–25 minutes✓
🛠️Module practice: Project B, part 3, safe and fast SQL
- An "place an order" transaction (order, items, stock) and a "record a payment" transaction (payment, order status), tested for failure and rollback.
- A stock constraint preventing overselling.
- Indexes for every foreign key and your report queries' filters, each justified by a query plan before and after.
- One N+1 problem found and fixed. Notes in
schema.md. Commit.
✅Module check
Explain in a few sentences, in your own words:
How do transactions keep data correct, and how do indexes make queries fast?
Show a good answer
A good answer mentions: a transaction groups changes so all or none happen (atomicity), constraints stay satisfied (consistency), concurrent transactions don't see each other's partial work (isolation), and committed data survives crashes (durability); updating relative to current values or locking rows prevents lost updates. Indexes are sorted lookups that avoid full scans, best on foreign keys and common filters, at a small cost to writes; query plans show whether they're used. Common slowdowns like N+1 queries, unbounded lists and long transactions are fixed first.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
