An index at the back of a book jumps you to a topic without reading every page — a database index does the same for queries. A transaction is like a bank transfer: the money leaves one account and lands in the other, all-or-nothing, never half-done.
Speed and safety
An index is a data structure (often a B-tree) that lets the database find rows by a column's value without scanning the whole table — turning a slow linear search into a fast lookup. A transaction groups several operations so they succeed or fail together, keeping data consistent.
Indexes speed up reads but slow down writes (each insert/update must maintain the index) and use extra storage. You index the columns you filter or join on, not every column.
Transferring money: debit one account and credit another inside one transaction. If either step fails, the whole transaction rolls back — you never lose or double the money (atomicity).
- A bank transfer debits account A, then credits account B.
- Imagine the system crashes right after the debit.
- Explain how a transaction prevents money vanishing.
What you should see: Because the two operations are one atomic transaction, a crash rolls back the debit — either both happen or neither does.