sqlite3: The SQLite Shell
Get fluent in the sqlite3 shell — open a database file, run queries, format and export results with dot-commands, read schema and data from files, read a query plan, and make the client your own.
SQLite is the database you already have — a single file, no server, shipped inside phones, browsers and countless apps. The way you meet it on a box is its shell, sqlite3: a REPL much like psql, but with its own personality. We start from an empty prompt and build real fluency one small thing at a time: opening a database file, switching from its ugly default output to clean Unicode tables, loading schema and data from files, querying and summarising, reading a query plan to see when an index is missing, importing and exporting CSV, and finally shaping the client with a startup file. Writing a query and running it are taught as separate steps, so each idea lands on its own.
What you'll build
- Open a SQLite database file and tell SQL statements from dot-commands
- Format results as Unicode tables and turn on headers
- Load schema and data from .sql files
- Read, order and summarise query results
- Read a query plan and add an index that changes it
- Import and export CSV, and customise the shell with a .sqliterc
Contents
- Open a database
- Run your first query
- Finish a statement you started
- Leave the shell
- Make the output readable
- List the tables
- Write a schema file
- Run a file from the prompt
- See the schema
- Add a second table
- Apply the updated schema
- See both tables
- Turn on foreign keys
- Write a seed file
- Load the data
- Read a result
- Summarise with aggregates
- Write a reusable query
- Run the saved query
- See how a query runs
- Write an index
- Apply the index and re-plan
- Time a query
- Write a CSV to import
- Import the CSV
- Export the next result
- Check the exported file
- Write a startup file
- See it take effect