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,960
  • 31
  • 73
  • 121

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,485
  • 28
  • 81
  • 134
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
  • 67,150
  • 23
  • 161
  • 242