You could define id
as an auto increment column:
create table entries (id integer primary key autoincrement, data)
As MichaelDorner notes, the SQLite documentation says that an integer primary key
does almost the same thing and is slightly faster. A column of that type is an alias for ROWID
, which behaves like an autoincrement column with the difference that without AUTOINCREMENT
the ID of the row might be reused. “In other words, the purpose of AUTOINCREMENT
is to prevent the reuse of ROWIDs from previously deleted rows.”[source]
create table entries (id integer primary key, data)
This behavior is implicit and could catch inexperienced SQLite developers off-guard.