VACUUM (SQLite)
VACUUM (SQLite) is a SQL statement in the SQLite Specific category. SQLite: reclaims disk space by rebuilding the entire database file. Needed because SQLite rarely shrinks automatically. The syntax is VACUUM;. It returns compacted database. A typical example: DELETE FROM logs WHERE created_at < '2025-01-01'; -- Data is deleted, but disk space is NOT reclaimed VACUUM; -- Rebuilds the DB file, reclaiming the freed space -- VACUUM INTO 'path' (SQLite 3.27+): creates a compacted copy VACUUM INTO 'compacted.db'; A close relative is AUTOINCREMENT (SQLite), which sQLite: unlike AUTO_INCREMENT in MySQL, only INTEGER PRIMARY KEY columns auto-increment. AUTOINCREMENT guarantees unique increasing IDs. A close relative is ROWID / _ROWID_, which sQLite: every row has an implicit 64-bit ROWID. INTEGER PRIMARY KEY becomes an alias for ROWID. A close relative is ATTACH DATABASE, which sQLite: connects another database file to the current connection, allowing cross-database queries. More about this category: SQLite-specific features — AUTOINCREMENT, ATTACH, VACUUM, PRAGMA, ROWID.