SQLite
PRAGMA Statements
Configure SQLite behavior and inspect the database.
By EZ4Code Team
pragmaconfigurationwal
Code
-- Foreign keys (off by default)
PRAGMA foreign_keys = ON;
PRAGMA foreign_keys; -- show current value
-- WAL mode for better concurrency
PRAGMA journal_mode = WAL;
PRAGMA wal_autocheckpoint = 1000;
-- Performance tuning
PRAGMA synchronous = NORMAL; -- FULL | NORMAL | OFF
PRAGMA cache_size = -20000; -- 20MB negative = kibibytes
PRAGMA temp_store = MEMORY;
PRAGMA mmap_size = 268435456; -- 256MB memory-mapped I/O
-- Introspection
PRAGMA table_info(users);
PRAGMA index_list(posts);
PRAGMA database_list;
PRAGMA integrity_check;Explanation
PRAGMA statements configure SQLite at runtime, with foreign_keys and journal_mode being the most impactful. WAL mode allows concurrent readers and a single writer, dramatically improving throughput. synchronous=NORMAL is safe in WAL mode and far faster than the default FULL, trading durability for speed.
More SQLite Snippets
Create Table
Define tables with constraints and autoincrement keys.
Insert & Query
Insert rows and query with parameterized statements.
JOINs & Aggregates
Combine tables and aggregate grouped rows.
Indexes & EXPLAIN
Create indexes and inspect query plans.
Transactions & Savepoints
Wrap statements in atomic units with savepoints.
ATTACH Database
Query across multiple database files in one connection.