SQLite for Mere Mortals
SQLite is a database that lives in a single file.
No server to install, no accounts, no ports: you open
library.db and you're talking SQL to your data. It's
also, quietly, the most deployed database on Earth —
inside every phone, every browser, most apps you've
ever used, and (if you run certain projects from a
certain guide author) a BBS simulator and a Usenet
catalog or two.
This guide assumes you can use a terminal and edit a text file. No database experience is assumed; SQL is taught as it's used.
What this guide covers
- What SQLite is — the file that is a database, and where it's already running in your life
- Your first database — the
sqlite3shell, dot-commands, creating and filling tables - Querying —
SELECTwith manners: filters, sorting, limits, aggregates - Keys and constraints — primary keys, uniqueness, and the foreign-key trap
- Joins — questions that need two tables
- Indexes and speed — why a query was slow and the one-command fix, measured
- Changing data safely — updates, deletes, and transactions that let you undo
- SQLite quirks — flexible types, NULL's strange logic, dates that are text
- JSON in SQLite — documents in tables, queried properly
- Files, backups, and care —
.backup,.dump, WAL, and checking a database's health - From code — the same database from Python, with safe parameters
- When not to use SQLite — one writer, network filesystems, and honest limits
- Troubleshooting — symptom → fix, with the real error messages
- Glossary — the terms, collected in one place
What it doesn't cover
Running a multi-user database server (that's SQLite's cousins' job), SQL beyond the practical middle, and database design theory past the working rules given here.
How to use this guide
Every command was run for real against SQLite 3.45 —
including a 100,000-row table built to measure an index
(0.020s → 0.000s), a transaction rolled back mid-flight,
a backup restored, JSON documents queried, and a write
refused with database is locked while another
connection held the file. The
examples/ build the same library
database the chapters use.
Part of the series
This guide is one of the For Mere Mortals guides: plain-language guides to the tools programmers and makers use.
Related guides:
License
The writing in this guide is licensed under CC BY 4.0. Code examples and lab scripts are licensed under the MIT License.