Background
Just recently, I learn that using AUTOINCREMENT
in SQLite is not encouraged.
CodePudding user response:
You don't need to achieve the same in Android room. In SQLite, a column with the type of INTEGER PRIMARY KEY
is an alias for the ROWID, except if you specify WITHOUT ROWID
.
So, upon insert your id
will receive an unused integer unless specified otherwise.
The reason for not recommending the AUTOINCREMENT
keyword is that unless it's a PRIMARY KEY
, then it is unlikely necessary to accept the costs in terms of CPU, memory usage, disk space and I/O overhead. However, using a PRIMARY KEY
is in fact a good idea. Note that the page you have shared never claims you should not use a PRIMARY KEY
, it just discourages the usage of the AUTOINCREMENT
keyword.