SQLite3
Command Reference

A complete reference of commonly used SQLite3 commands and use cases.

DOT

Dot Commands — Shell Meta-Commands

These start with a dot and are not SQL — they control the SQLite shell itself.

CommandDescription
.helpShow all available dot commands
.quit / .exitExit the SQLite shell
.databasesShow currently open database(s)
.tablesList all tables in the database
.schemaShow CREATE statements for all tables
.schema tablenameShow structure of a specific table
.mode columnDisplay results in aligned columns
.headers onShow column headers in results
.output file.txtSave query results to a file
.output stdoutReturn output back to screen
.read file.sqlExecute SQL from a file
.import file.csv tablenameImport CSV data into a table
.dumpExport entire database as SQL
.dump tablenameExport a specific table as SQL
DDL

Data Definition — Creating Structure

Commands for creating and modifying database structure.

-- Create a table
CREATE TABLE patients (
    id      INTEGER PRIMARY KEY AUTOINCREMENT,
    name    TEXT NOT NULL,
    age     INTEGER,
    created DATE DEFAULT (date('now'))
);

-- Modify a table (add column)
ALTER TABLE patients ADD COLUMN phone TEXT;

-- Delete a table
DROP TABLE patients;
DML

Data Manipulation — Managing Data

Commands for inserting, updating, and deleting data.

-- Insert data
INSERT INTO patients (name, age) VALUES ('João Silva', 35);

-- Update data
UPDATE patients SET age = 36 WHERE id = 1;

-- Delete a specific row
DELETE FROM patients WHERE id = 1;

-- Delete all rows
DELETE FROM patients;
DQL

Data Query — Reading Data

Commands for retrieving and filtering data.

-- Select all
SELECT * FROM patients;

-- Select specific columns
SELECT name, age FROM patients;

-- Filter with condition
SELECT * FROM patients WHERE age > 30;

-- Sort results
SELECT * FROM patients ORDER BY name ASC;

-- Limit results
SELECT * FROM patients LIMIT 10;

-- Count rows
SELECT COUNT(*) FROM patients;

-- Search with pattern
SELECT * FROM patients WHERE name LIKE 'João%';
JOIN

Joins — Combining Tables

Commands for combining data from multiple related tables.

-- Inner join (only matching rows)
SELECT patients.name, appointments.date
FROM patients
INNER JOIN appointments ON patients.id = appointments.patient_id;

-- Left join (all patients, with or without appointments)
SELECT patients.name, appointments.date
FROM patients
LEFT JOIN appointments ON patients.id = appointments.patient_id;
FN

Useful Functions

Built-in functions for dates, strings, and aggregation.

-- Date and time
SELECT date('now');          -- current date
SELECT datetime('now');      -- current date and time

-- String functions
SELECT upper(name) FROM patients;
SELECT length(name) FROM patients;

-- Aggregate functions
SELECT AVG(age) FROM patients;
SELECT MAX(age) FROM patients;
SELECT MIN(age) FROM patients;
SELECT SUM(age) FROM patients;
BAK

Backup & Export

Commands for exporting and backing up your database.

-- Export entire database to SQL file
.output backup.sql
.dump
.output stdout

-- Export table to CSV
.headers on
.mode csv
.output patients.csv
SELECT * FROM patients;
.output stdout
💡 Tip: Unlike MySQL, SQLite has no central server. Each .db file is the database — back it up simply by copying the file.