Click here to Skip to main content
11,583,555 members (68,279 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Sqlite
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 14-Nov-11 0:53am
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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!
  Permalink  
Comments
Mehdi Gholam at 14-Nov-11 7:08am
   
my 5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use this (where tablename is your table):

DELETE FROM tablename;    
DELETE FROM sqlite_sequence WHERE name = 'tablename';
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 390
1 Dave Kreskowiak 230
2 Sergey Alexandrovich Kryukov 210
3 virusstorm 209
4 Richard Deeming 180
0 OriginalGriff 1,523
1 Sergey Alexandrovich Kryukov 995
2 Abhinav S 696
3 Dave Kreskowiak 621
4 Suvendu Shekhar Giri 568


Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 14 Nov 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100