SQLite Cheat Codes
SQLite Cheat Codes for single-file databases, WAL mode, pragmas, and FTS5 search. 20 essential cheat codes ready to copy and execute.
Fetch columns from SQLite database.
SELECT col1, col2 FROM tbl; SELECT id, name FROM notes; Filter output rows.
SELECT * FROM tbl WHERE col = val; SELECT * FROM tasks WHERE completed = 1; Join two tables on condition.
SELECT * FROM t1 JOIN t2 ON t1.id = t2.fk; SELECT n.title, c.name FROM notes n JOIN categories c ON n.cat_id = c.id; Group rows for aggregate stats.
SELECT col, COUNT(*) FROM tbl GROUP BY col; SELECT category, COUNT(*) FROM tasks GROUP BY category; Sort output rows.
SELECT * FROM tbl ORDER BY col DESC; SELECT * FROM notes ORDER BY updated_at DESC; Paginate SQLite query output.
SELECT * FROM tbl LIMIT count OFFSET skip; SELECT * FROM logs LIMIT 20 OFFSET 40; Add new row into table.
INSERT INTO tbl (col) VALUES (val); INSERT INTO notes (title) VALUES ('Meeting Summary'); Modify column values in rows.
UPDATE tbl SET col = val WHERE condition; UPDATE tasks SET completed = 1 WHERE id = 5; Remove records matching filter.
DELETE FROM tbl WHERE condition; DELETE FROM temp_files WHERE age > 7; Execute upsert on unique key collision.
INSERT INTO tbl (id, val) VALUES (1, 'a') ON CONFLICT (id) DO UPDATE SET val = excluded.val; INSERT INTO kv (key, val) VALUES ('theme', 'dark') ON CONFLICT (key) DO UPDATE SET val = excluded.val; Inspect table columns and data types.
PRAGMA table_info('tbl'); PRAGMA table_info('users'); Enable high-concurrency WAL mode.
PRAGMA journal_mode = WAL; PRAGMA journal_mode = WAL; Reclaim unused file disk space.
VACUUM; VACUUM; Build full-text search index.
CREATE VIRTUAL TABLE fts_tbl USING fts5(col1, col2); CREATE VIRTUAL TABLE docs_fts USING fts5(title, body); Execute full-text search query.
SELECT * FROM fts_tbl WHERE fts_tbl MATCH 'query'; SELECT * FROM docs_fts WHERE docs_fts MATCH 'sqlite OR database'; Extract JSON field value.
SELECT json_extract(json_col, '$.key') FROM tbl; SELECT json_extract(data, '$.user.name') FROM events; Attach secondary database file.
ATTACH DATABASE 'file.db' AS alias; ATTACH DATABASE 'archive.db' AS archive; Manipulate timestamps and dates.
SELECT datetime('now', 'start of month'); SELECT datetime('now', '-7 days'); Enable foreign key constraint checks.
PRAGMA foreign_keys = ON; PRAGMA foreign_keys = ON; Enforce strict column data types.
CREATE TABLE tbl (id INT PRIMARY KEY) STRICT; CREATE TABLE accounts (id INT PRIMARY KEY, balance REAL) STRICT; No cheat codes found matching your search term.