I have this method which will remove all rows from a table but I also want it to reset the autoincrement so that when a new row is added it will start again. The SQL stateme
I was trying too hard.
Finally, I got this answer code...
Book.deleteAll(Book.class);
book=new Book(user, pass);
book.setId(Long.valueOf(book.listAll(Book.class).size()));
book.save();
this code work like delete and recreating the table.and reset id.
good luck
you'll need single quotes around your table name, i.e.
db.execSQL("DELETE FROM SQLITE_SEQUENCE WHERE NAME = '" + TABLE_NAME + "'");
you can also use delete() method of SQLiteDatabase, like this
db.delete("SQLITE_SEQUENCE","NAME = ?",new String[]{TABLE_NAME});
Building on dldnh's answer:
The following query will set seq
to the largest value in the col
identity column in the Tbl
table, so there is no risk of violating constraints.
UPDATE sqlite_sequence SET seq = (SELECT MAX(col) FROM Tbl) WHERE name="Tbl"