Pierre Lebon
Pierre Lebon

Reputation: 463

SQLite: Reset primary key field error

i am working with sqlite and i need to reset the auto increment values, I found on StackOverflow:

SQLite Reset Primary Key Field

but when i do

delete from sqlite_sequence where name='my_table';

all I got is :

Error: no such table: sqlite_sequence

Did someone know the problem ? I am on an iMac with sqlite3.

Thanks for help ! Have a nice day

Upvotes: 0

Views: 754

Answers (2)

CL.
CL.

Reputation: 180260

There are two types of autoincrementing columns, ones declared as INTEGER PRIMARY KEY, and ones declared as INTEGER PRIMARY KEY AUTOINCREMENT.

Columns with AUTOINCREMENT have a record in the sqlite_sequence table, and can be reset with the above DELETE statement.

Plain INTEGER PRIMARY KEY columns are still autoincrementing, but derive the next value from the largest actual value in the table. These can be simply reset by deleting all records from the data table itself.

Upvotes: 3

Edper
Edper

Reputation: 9322

I tested it on my own sqlite DB and it works fine.

See my Fiddle Demo.

Maybe in your case it could simply be a mistake of your spelling of your table name? Or a misspelling on keyword sqlite_sequence maybe.

Upvotes: 0

Related Questions