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
Open a database file
sqlite3 app.db

# Start the sqlite3 shell with a file-backed database.

Open an in-memory database
sqlite3 :memory:

# Start a temporary database that lives only for the session.

List attached databases
.databases

# Show the main database and any attached files.

List tables
.tables

# Show table names in the current database.

Show full schema
.schema

# Print CREATE statements for the whole database.

Show schema for one table
.schema users

# Print the CREATE statement for a specific object.

Show schema plus sqlite_stat tables
.fullschema

# Include internal objects useful for advanced debugging.

List shell commands
.help

# Display available dot-commands.

## Output, import, and export
Show column headers
.headers on

# Enable headers in tabular output.

Use aligned column output
.mode column

# Render query results in a readable table.

Export rows as CSV
.mode csv

# Switch output mode to CSV.

Import a CSV file into a table
.import ./users.csv users

# Load rows from CSV using the shell importer.

Execute SQL from a file
.read ./schema.sql

# Run a script inside the shell.

Dump the full database as SQL
.dump

# Export schema and data as executable SQL.

Write the next query result to a file
.once users.csv

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

Attempt recovery from a damaged database
.recover

# Use the shell recovery command.

Recommended next

No recommendations yet.