Database / SQLite Interview questions
What is AUTOINCREMENT in SQLite?
AUTOINCREMENT is an optional modifier on an INTEGER PRIMARY KEY column that
guarantees newly generated key values are always strictly larger than any value ever used before in that
table, even after rows with high key values have been deleted — preventing key value reuse.
CREATE TABLE person ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT );
Without AUTOINCREMENT, a plain INTEGER PRIMARY KEY already auto-generates
sequential-ish values by default (typically one more than the current maximum), but it can reuse a
previously deleted row's key value under certain conditions. AUTOINCREMENT adds a small amount of
extra bookkeeping overhead (an internal tracking table) specifically to guarantee that never happens, which
matters if your application logic depends on IDs never repeating even after deletions.
More Related questions...