SQLite VDBE opcode

FkCheck

Halt with an SQLITE_CONSTRAINT error if there are any unresolved foreign key constraint violations.

An example

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

INSERT INTO artists VALUES (NULL, 'New', 'US') RETURNING id
addropcodep1p2p3p4p5
0Init04000
1OpenWrite02030
2OpenWrite170k(2,,)0
3OpenWrite260k(2,,)0
4SoftNull2000
5String8030New0
6String8040US0
7NewRowid0100
8HaltIfNull129923artists.name1
9NotExists01110
10Halt155520artists.id2
11Affinity230DBB0
12SCopy31200
13PureFunc0126lower(1)32
14IntCopy1700
15MakeRecord6250
16SCopy3900
17IntCopy11000
18MakeRecord9280
19MakeRecord23110
20FkIfZero02700
21OpenRead33020
22Rewind32700
23Column31120
24Ne12612BINARY-883
25FkCounter0-100
26Next32301
27IdxInsert156216
28IdxInsert289216
29Insert0111artists57
30Copy11400
31MakeRecord141150
32NewRowid51600
33Insert515160
34FkCheck0000
35Rewind53900
36Column50140
37ResultRow14100
38Next53600
39Halt0000
40Transaction01101
41OpenEphemeral5100
42Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Affinity, Column, Copy, FkCounter, FkIfZero, Goto, Halt, HaltIfNull, IdxInsert, Init, Insert, IntCopy, MakeRecord, Ne, NewRowid, Next, NotExists, OpenEphemeral, OpenRead, OpenWrite, PureFunc, ResultRow, Rewind, SCopy, SoftNull, String8, Transaction.

What the SQLite documentation says

Halt with an SQLITE_CONSTRAINT error if there are any unresolved foreign key constraint violations. If there are no foreign key constraint violations, this is a no-op.

FK constraint violations are also checked when the prepared statement exits. This opcode is used to raise foreign key constraint errors prior to returning results such as a row change count or the result of a RETURNING clause.

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.

← FinishSeek · FkCounter →