Search notes:

SQLite: sqlite_sequence (internal schema object)

The SQLite internal table sqlite_sequence is used to store information about autoincrement columns. In fact, it is created when the first table with an autoincrement column is created.

Structure of sqlite_sequence

The structure of sqlite_sequence can be displayed with the SQLite shell command .schema sqlite_sequence. Because sqlite_sequence is only created when the first table with an autoincrement column exists, we first need to create such a table.
create table dummy (id integer primary key autoincrement);
.schema sqlite_sequence
--
-- CREATE TABLE sqlite_sequence(name,seq);
As can be seen, sqlite_sequence has the two columns

Example

create table tq84_tab (
  id   integer primary key autoincrement,
  col
);

insert into tq84_tab (col) values ('foo');
insert into tq84_tab (col) values ('bar');

select * from sqlite_sequence where name = 'tq84_tab';
--
-- tq84_tab|2

insert into tq84_tab values(5, 'five');

select * from sqlite_sequence where name = 'tq84_tab';
--
-- tq84_tab|5

insert into tq84_tab (col) values ('baz');
select id from tq84_tab where col = 'baz';
--
-- 6

select * from sqlite_sequence where name = 'tq84_tab';
--
-- tq84_tab|6

drop table tq84_tab;
Github repository about-sqlite, path: /internal-schema-objects/sqlite_sequence/example.sql

See also

Internal schema objects

Index