How to insert a unique ID into each SQLite row?
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 the same thing and is slightly faster. A column of that type is an alias for rowid
, which behaves like an autoincrement column.
create table entries (id integer primary key, data)
This behavior is implicit and could catch inexperienced SQLite developers off-guard.