Click here to Skip to main content
15,860,859 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
i have an sqlite table with primarykey,autoincrement Id field.
Once i use the delete command to remove all rows and after this when i try to insert the Id field is not starting from 0, instead its starting from previous max+1 value.
In mysql if we use empty table command and insert again , then we get the Id starting from 1 again.
How can i achieve the same in sqllite.
My real aim is once the table contains 1000 records i want to remove all records and start from id=1 again
Posted

You can drop and recreate the table, or
delete from sqlite_sequence where name='%TABLE NAME%'; 

More info:
http://sqlite.org/autoinc.html[^]

Good luck!
 
Share this answer
 
Comments
Mehdi Gholam 14-Nov-11 7:08am    
my 5!
Use this (where tablename is your table):

SQL
DELETE FROM tablename;    
DELETE FROM sqlite_sequence WHERE name = 'tablename';
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900