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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1738741518, '3.139.69.151', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/SQLite/internals/schema-objects/sqlite_sequence(86): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78