SQLite CLI and Shell Cheatsheet

sqlite3 shell commands for opening databases, inspecting schema, formatting output, importing CSV, and scripting common interactive workflows.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Open and inspect databases

Start sqlite3, open files, inspect databases, and discover schema objects.

Open a database file

Start the sqlite3 shell with a file-backed database.

bashANYsqlite3opendatabase
bash
sqlite3 app.db

Creates the file if it does not exist and opens an interactive shell session.

Open an in-memory database

Start a temporary database that lives only for the session.

bashANYsqlite3memorytesting
bash
sqlite3 :memory:

Useful for quick experiments, demos, and throwaway SQL tests.

List attached databases

Show the main database and any attached files.

textANYsqlite3databasesattach
text
.databases

Displays the database aliases and file paths known to the current connection.

List tables

Show table names in the current database.

textANYsqlite3tablesschema
text
.tables

Fast way to discover tables and virtual tables from the shell.

Show full schema

Print CREATE statements for the whole database.

textANYsqlite3schemaddl
text
.schema

Good for inspecting tables, indexes, triggers, and views.

Show schema for one table

Print the CREATE statement for a specific object.

textANYsqlite3schematable
text
.schema users

Limits output to matching objects, which is easier to read in larger databases.

Show schema plus sqlite_stat tables

Include internal objects useful for advanced debugging.

textANYsqlite3fullschemaplanner
text
.fullschema

Helpful when investigating query-planner behavior and generated internal objects.

List shell commands

Display available dot-commands.

textANYsqlite3helpdot-commands
text
.help

Useful when working on a new machine or less-familiar sqlite3 version.

Output, import, and export

Format results, run scripts, import CSV, and dump databases.

Show column headers

Enable headers in tabular output.

textANYsqlite3headersoutput
text
.headers on

Often paired with `.mode column` for human-readable query results.

Use aligned column output

Render query results in a readable table.

textANYsqlite3modecolumn
text
.mode column

Great for interactive browsing in a terminal.

Export rows as CSV

Switch output mode to CSV.

textANYsqlite3csvexport
text
.mode csv

Useful before redirecting or writing query output to a file.

Import a CSV file into a table

Load rows from CSV using the shell importer.

textANYsqlite3importcsv
text
.import ./users.csv users

Make sure the target table exists first or use a staging table for cleanup.

Execute SQL from a file

Run a script inside the shell.

textANYsqlite3readscripts
text
.read ./schema.sql

Useful for schema initialization, migrations, or repeatable demos.

Dump the full database as SQL

Export schema and data as executable SQL.

textANYsqlite3dumpbackup
text
.dump

Helpful for backups, migrations, and reproducible fixtures.

Write the next query result to a file

Send one result set to a file without changing subsequent output.

textANYsqlite3onceoutput
text
.once users.csv

Combine with `.mode csv` and a `SELECT` statement to export a query result.

Attempt recovery from a damaged database

Use the shell recovery command.

textANYsqlite3recovercorruption
text
.recover

Can salvage data from a corrupt database into SQL output for rebuilding.

Recommended next

No recommendations yet.