SQLite Dot Commands
Dot commands are CLI shortcuts for shell-level tasks like listing tables, showing schema, and changing output formatting.
They are essential for fast exploration while learning.
Core Concepts
flowchart TD
A[Need data?] --> B{SQL or shell task?}
B -->|Data query| C[Use SQL statement]
B -->|Shell/metadata| D[Use dot command]
| Dot command | Purpose | Example |
|---|---|---|
.help | List available dot commands | .help |
.databases | Show attached DB files | .databases |
.tables | List tables/views | .tables |
.schema | Show CREATE statements | .schema |
.mode | Set output mode | .mode column |
.headers | Show/hide column names | .headers on |
Code Examples
-- Show shell help for dot commands.
.help
| Expected output |
|---|
| A long list of available dot commands and descriptions. |
-- Improve readability of query results.
.mode column
.headers on
SELECT 'Alice' AS name, 95 AS score;
| name | score |
|---|---|
| Alice | 95 |
SQLite-Specific Nuances
SQLite Nuance
Dot commands are interpreted by sqlite3 itself.
If you send .tables through an application driver, it will fail because it is not SQL.
Common Pitfalls / Best Practices
Pitfall
Trying to run multiple dot commands in the middle of unfinished SQL input.
Finish or cancel SQL input first, then run dot commands.
Best Practice
Start each learning session with .headers on and .mode column so outputs are easier to read.
Quick Challenge
Set readable output and run a query that returns topic and level.
View Solution
.headers on
.mode column
SELECT 'CLI' AS topic, 'beginner' AS level;
| topic | level |
|---|---|
| CLI | beginner |