Reputation: 12803
I have created a SQLite table by using query below
db.execSQL("create table " + TABLE__WORK + " ( " + ID1 + " INTEGER PRIMARY KEY ,Name TEXT, Title TEXT, Time TEXT, Date TEXT)");
The ID now can be auto-incremented. But after I perform delete query, delete the first row data and add again, the ID will start from 1
instead of 2
. Is it possible to make the id become 2
?
Upvotes: 1
Views: 17968
Reputation: 12382
Make it INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
.
Here's what the SQLite Autoincrement document say:
If the
AUTOINCREMENT
keyword appears afterINTEGER PRIMARY KEY
, that changes the automaticROWID
assignment algorithm to prevent the reuse ofROWIDs
over the lifetime of the database. In other words, the purpose ofAUTOINCREMENT
is to prevent the reuse ofROWIDs
from previously deleted rows.
Upvotes: 3
Reputation: 48327
SQLite AUTOINCREMENT is a keyword used for auto incrementing a value of a field in the table.You do not need ID1
.
See reference here
Please use this:
db.execSQL("create table " + TABLE__WORK + " (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,Name TEXT, Title TEXT, Time TEXT, Date TEXT)");
Upvotes: 8