How can I reset a autoincrement sequence number in sqlite How can I reset a autoincrement sequence number in sqlite sqlite sqlite

How can I reset a autoincrement sequence number in sqlite


Building on Marcos Vasconcelos' answer:

UPDATE sqlite_sequence SET seq = (SELECT MAX(col) FROM Tbl) WHERE name="Tbl"

This 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.


Inside your .db file there's an table called sqlite_sequence

Each row has two columnsname which is the name of the tableseq a integer indicating the current last value at this table

You can update it to 0

But beware if your table use this id as the unique identifier.


UPDATE SQLITE_SEQUENCE SET SEQ= 'value' WHERE NAME='table_name';