What does SQLite AUTOINCREMENT change about row IDs?
Quick answer
In a standard SQLite rowid table, INTEGER PRIMARY KEY already assigns an ID when you omit it or insert NULL. AUTOINCREMENT changes automatic allocation so a committed row ID is not reused later for that table. It does not guarantee consecutive, gapless IDs, and it adds overhead. Use it only when preventing reuse of previously committed IDs matters; otherwise, the ordinary key is usually enough. [S1]
The question, the details, the next step.
A practical checklist
Confirm the table is a SQLite rowid table using
INTEGER PRIMARY KEY.Decide whether preventing automatic reuse of a previously committed ID is a real requirement.
Do not expect consecutive or gapless IDs; failed inserts can leave gaps.
Consider the documented CPU, memory, disk-space, and I/O overhead before adding
AUTOINCREMENT.Write down whether the ID is an internal row identifier or has another purpose.
A few more useful answers
Does AUTOINCREMENT prevent every possible repeated ID?
The cited guarantee concerns automatically selected row IDs and preventing reuse of previously committed IDs under SQLite’s documented table and key conditions. It does not establish a guarantee for every way an identifier might be supplied or every schema type. [S1]
Can I use AUTOINCREMENT to create invoice numbers without gaps?
No. It does not guarantee gapless or consecutive numbering, and failed inserts can leave gaps. The cited SQLite behavior does not specify a business-numbering system. [S1]
Is AUTOINCREMENT usually necessary?
SQLite says it is usually unnecessary because it adds CPU, memory, disk-space, and I/O overhead. Use it when preventing automatic reuse of previously committed row IDs is specifically required. [S1]
Sources
References used for this guide.
- [S1] SQLite AUTOINCREMENT: row ID allocation, reuse, and tradeoffs sqlite.org · Checked
