Almost always: don't use AUTOINCREMENT
The keyword AUTOINCREMENT exists in SQLite, but its semantics are subtler than most developers expect — and slower than the default behavior.
- Default INTEGER PRIMARY KEY — SQLite picks the next available rowid. If you delete rows, the engine may reuse the deleted ids.
- INTEGER PRIMARY KEY AUTOINCREMENT — adds a guarantee: ids are monotonically increasing, never reused, even after deletes. Implemented via an internal
sqlite_sequencetable that tracks the highest-ever-used rowid.
The cost: every insert touches sqlite_sequence, which adds an extra page write. The benefit is rarely needed — most application code does not depend on the database to never reuse ids. If you need globally-unique ids, use UUIDs in a TEXT column with WITHOUT ROWID instead.
Warning: Once you commit to AUTOINCREMENT on a table you can't migrate away from it without the CTAS dance. Decide up-front whether you actually need the no-reuse guarantee.