0

I am using sqlite in my android application.

When i delete all the records from the table then also the next entry is the increment of the last serial.If i delete all records from table,I need to start it from 1 How to do it?

coderslay
  • 13,230
  • 29
  • 72
  • 118

2 Answers2

4

It sounds like you want to reset your AUTO_INCREMENT to 0.

DELETE FROM tablename;
DELETE FROM SQLITE_SEQUENCE WHERE name='tablename';
Dan Kanze
  • 18,385
  • 28
  • 80
  • 133
1

You can do it like this,

delete from sqlite_sequence where name='your_table';  

Altering SQLITE_SEQUENCE Table is not a good option because it is likely to disturb AUTOINCREMENT Key generation Algorithm. You can see this Answer.

Community
  • 1
  • 1
Lalit Poptani
  • 66,608
  • 21
  • 157
  • 241