Databases for analysts: indexes, views, locks and transactions
Know what an index, a view and a transaction do, how locks keep writers apart, and which questions to ask when a report is slow or a change stops half way.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a library. A card catalogue finds a book without a walk down every shelf. A glass case shows a chosen set of books and keeps no second copy. Borrowing rules stop two people taking the last copy.
Daily List is a made-up to-do app (SYNTHETIC / TRAINING ONLY). The Monday report is slow. Nina, the , asks Sam, the , what to do. Sam does not tune the database. He asks Leo, the developer, to show the plan.
What it is: (Structured Query Language) is a language for asking a database questions and for changing it. A table is a grid. A row is one task. A column is one fact, such as the title. A is a separate sorted structure the database uses to jump to matching rows instead of reading the whole table. A database view is a saved query that you use like a table, and it holds no rows of its own. A database transaction is a group of changes that the database saves all together, or not at all. You meet all three inside the database program, such as PostgreSQL or SQLite. A view's neighbour is a real table, which does store rows. A transaction's neighbour is one lone statement, which cannot undo a half-finished move.
Why it matters: Without an index, a large tasks table is read from the first row to the last, and Nina waits. Without a transaction, a move can finish one step and fail the next, so a task sits on the wrong list. Sam's job is to ask for the plan and to ask what happens if stops halfway.
One library desk serves a few readers. A database may serve many people at the same time.
PLAIN WORDS · 1 in this section
- sqlite
- a small free database tool
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the work.
THE REAL JOB The picture helps a newcomer remember that an index finds, a view shows and a transaction keeps a group of changes together.
- Ask for the plan
- Check the index
- Save a view
- Group the changes
- Let writers wait
HOW THE PICTURE MAPS
| In the picture | In the work |
|---|---|
| The card catalogue | A database index |
| The glass display case of chosen books | A database view |
| Borrowing a book and returning it as one visit | A transaction |
| Waiting for the last copy to come back | A lock |
| Walking every shelf to find a book | A sequential scan |
WHERE THIS PICTURE STOPS
- A library has one desk for a few readers, but a database may serve thousands at once.
- A catalogue card is written once. An index must be updated on every change.
- A display case holds real books. A view holds no data of its own.
HOOK
Find with the catalogue, show with the case, borrow by the rules.
REMEMBER IT THIS WAY
A chunk: a long list grouped so it is easier to hold.
Think library: the catalogue finds a book fast, the glass case shows chosen books, and borrowing rules make a visit all or none.
| In the trick | What it stands for |
|---|---|
| Catalogue | A database index finds rows without reading the whole table |
| Glass case | A database view is a saved query that shows chosen rows |
| Borrowing rules | A transaction saves all changes or none |
TELL A FRIEND
An index helps the database find rows fast, a view is a saved query, and a transaction keeps a group of changes together. Locks make a second writer wait.
OFTEN MIXED UP WITH SQL for BAs: statement types, keys and constraints. That topic names the families of Structured Query Language () and the rules a table enforces. This one covers speed, saved queries and all-or-nothing changes.
PRACTISE AND KEEP
Sources for this topic — 10 sources
- Market practice
CREATE INDEX (PostgreSQL documentation) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, CREATE INDEX options and maintenance/concurrent build scope; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: CREATE INDEX options and maintenance/concurrent build scope. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
CREATE VIEW (PostgreSQL documentation) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, CREATE VIEW: ordinary query definition, not materialized result; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: CREATE VIEW: ordinary query definition, not materialized result. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
Transactions (PostgreSQL tutorial) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, §3.4 explicit transactions and savepoints; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: §3.4 explicit transactions and savepoints. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
Transaction Isolation (PostgreSQL documentation, current version) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, §13.2 isolation levels and Read Committed snapshots; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: §13.2 isolation levels and Read Committed snapshots. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
Explicit locking, deadlocks (PostgreSQL documentation) ↗ — PostgreSQL Global Development Group · PostgreSQL 18, §13.3 row/table locking, deadlocks and ordinary-reader exceptions; publisher page opened6November 2026. Dialect scope explicit.
PostgreSQL18 publisher documentation opened on6November2026: §13.3 row/table locking, deadlocks and ordinary-reader exceptions. No execution on PostgreSQL is claimed; engine-specific examples remain scoped to18.
- Market practice
SQLite: ON CONFLICT resolution ↗ — SQLite project · SQLite: ON CONFLICT resolution; Default ABORT undoes the failing statement, preserving earlier pending statements. Publisher page opened6November 2026.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
- Market practice
SQLite: query planning ↗ — SQLite project · SQLite: query planning; Index lookup and covering-index source figures5/14; query planner concepts, no promised runtime multiplier. Publisher page opened6November 2026.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
- Market practice
PostgreSQL18: indexes on expressions ↗ — PostgreSQL Global Development Group · PostgreSQL 18: indexes on expressions; §11.7 expression index example lower(col), affected maintenance and non-HOT update scope. Publisher page opened6November 2026.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
- Simplified educational illustration
Payments Signal editorial teaching models — Payments Signal
What this simplifies: Daily List people, data and exercises are invented for teaching. Query results belong to the declared fixture and database version. Authorization, business identity, time bounds and unknown-value policy must be agreed in context; no universal mandatory query template is implied.
Used wherever diagrams, scenarios, figures, or example values are didactic constructions rather than sourced facts; every such use carries a simplifications disclosure. All people, companies, banks, and list entries in examples are fictional.
- Market practice
SQLite: public-domain dedication ↗ — SQLite project · SQLite copyright and public-domain declaration, publisher page opened 6 November 2026: basis for reusing the unchanged documentation figures shown in this lesson.
Publisher documentation opened on6November2026. Engine/version scope is explicit; other database implementations may differ. Teaching queries are synthetic, not a required publisher template.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.