Android SQLite auto increment

Make it INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL. Here’s what the docs say:

If a column has the type INTEGER PRIMARY KEY AUTOINCREMENT then… the ROWID chosen
for the new row is at least one larger than the largest ROWID that has
ever before existed in that same table.

The behavior implemented by the AUTOINCREMENT keyword is subtly
different from the default behavior. With AUTOINCREMENT, rows with
automatically selected ROWIDs are guaranteed to have ROWIDs that have
never been used before by the same table in the same database. And the
automatically generated ROWIDs are guaranteed to be monotonically
increasing.

Leave a Comment