Usually, when you clear the table, you also need to reset the self-increment column to zero. Here's how to define a self-increment column in SQLite:
1 |
CREATE TABLE TableName (id INTEGER PRIMARY KEY autoincrement, ...); |
A table named Sqlite_sequence is automatically created when the SQLite database contains a self-increment column. This table consists of two columns: name and seq. The name records the table where the increment column is located, and the SEQ record is the current ordinal (the number of the next record is the current ordinal plus 1). If you want to set the ordinal of a self-increment column to zero, you only need to modify the Sqlite_sequence table.
2 |
UPDATE sqlite_sequence SET seq = 0 WHERE name = ' TableName '; |
You can also delete the record directly:
3 |
DELETE from sqlite_sequence WHERE name = ' TableName '; |
To reset all the table's self-increment columns to zero, empty the Sqlite_sequence table directly:
Transact-SQL
|
DELETE from Sqlite_sequence; |
iOS Development database-SQLite clears the table and zeros the self-increment column