According to your SQL below, I think you created sqlite_autoindex_...
table with UNIQUE instead of sqlite_sequence table with AUTOINCREMENT. *sqlite_sequence
table is never ever created unless you create a table with an AUTOINCREMENT
column.:
ID' INTEGER NOT NULL UNIQUE ... PRIMARY_KEY('ID')
The doc says below:
Do not confuse automatic indexes with the internal indexes (having names like "sqlite_autoindex_table_N") that are sometimes created to implement a PRIMARY KEY constraint or UNIQUE constraint.
For example, you create test
table which has id
column with TEXT PRIMARY KEY
or TEXT UNIQUE
as shown below:
CREATE TABLE test (
id TEXT PRIMARY KEY
);
Or:
CREATE TABLE test (
id TEXT UNIQUE
);
Then, sqlite_autoindex_test_1
table is created as shown below. *My answer explains how to show column names:
sqlite> .headers on
sqlite> .mode box
sqlite> SELECT name FROM sqlite_master;
┌───────┬─────────────────────────┐
│ type │ name │
├───────┼─────────────────────────┤
│ table │ test │
│ index │ sqlite_autoindex_test_1 │
└───────┴─────────────────────────┘
In addition, you create test
table which has id
column with INTEGER PRIMARY KEY
as shown below:
CREATE TABLE test (
id INTEGER PRIMARY KEY
);
Then, sqlite_autoindex_test_1
table is not created as shown below.
sqlite> .headers on
sqlite> .mode box
sqlite> SELECT type, name FROM sqlite_master;
┌───────┬──────┐
│ type │ name │
├───────┼──────┤
│ table │ test │
└───────┴──────┘
But, you create test
table which has id
column with INTEGER UNIQUE
as shown below:
CREATE TABLE test (
id INTEGER UNIQUE
);
Then, sqlite_autoindex_test_1
table is created as shown below:
sqlite> .headers on
sqlite> .mode box
sqlite> SELECT name FROM sqlite_master;
┌───────┬─────────────────────────┐
│ type │ name │
├───────┼─────────────────────────┤
│ table │ test │
│ index │ sqlite_autoindex_test_1 │
└───────┴─────────────────────────┘
UNIQUE
on a primary key column is redundant and pointless, btw. – KomsomolAUTOINCREMENT
integer PK at some point and then drop it? – Komsomolsqlite_
and explicitly cannot be dropped once the system creates it. sqlite.org/fileformat2.html#the_sqlite_sequence_table – KomsomolUPDATE
command could do it but resetting/altering a sequence is most of the time a bad idea.. – CleveyAUTOINCREMENT
, a new rowid is calculated based on the current maximum rowid present in the table. See the link that forpas provided for a complete description of the algorithm. tl;dr: reset it by deleting all rows from the table. – Komsomol