SQLite VDBE opcode

NewRowid

Get a new integer record number (a.k.a "rowid") used as the key to a table.

An example

26 of the 178 statements we compiled against the sample database use NewRowid. This is the one with the shortest program; the rows that use NewRowid are highlighted.

CREATE TRIGGER t1 AFTER INSERT ON artists BEGIN SELECT 1; END
addropcodep1p2p3p4p5
0Init01300
1OpenWrite01050
2String8020trigger0
3String8030t10
4String8040artists0
5Integer0500
6String8060CREATE TRIGGER t1 AFTER INSERT ON artists BEGIN SELECT 1; END0
7NewRowid0100
8MakeRecord257BBBDB0
9Insert07124
10SetCookie0120
11ParseSchema000type='trigger' AND name='t1'0
12Halt0000
13Transaction01101
14Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Goto, Halt, Init, Insert, Integer, MakeRecord, OpenWrite, ParseSchema, SetCookie, String8, Transaction.

What the SQLite documentation says

Get a new integer record number (a.k.a "rowid") used as the key to a table. The record number is not previously used as a key in the database table that cursor P1 points to. The new record number is written written to register P2.

If P3>0 then P3 is a register in the root frame of this VDBE that holds the largest previously generated record number. No new record numbers are allowed to be less than this value. When this value reaches its maximum, an SQLITE_FULL error is generated. The P3 register is updated with the ' generated record number. This P3 mechanism is used to help implement the AUTOINCREMENT feature.

From sqlite.org's list of opcodes for SQLite 3.54.1, in the public domain. Opcodes are not a stable interface and change between releases.

← Ne · Next →