SQLite VDBE opcode

Destroy

Delete an entire database table or index whose root page in the database file is given by P1.

An example

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

DROP TABLE notes
addropcodep1p2p3p4p5
0Init03700
1Null0100
2OpenWrite01050
3Rewind01100
4Column0220
5Ne3102BINARY-882
6Column0020
7Eq4102BINARY-882
8Rowid0500
9Delete0002
10Next0401
11Destroy11200
12Null0670
13OpenEphemeral2060
14IfNot22210
15OpenRead11040
16Rewind12200
17Column13130
18Ne22113BINARY-884
19Rowid1700
20Insert2670
21Next11701
22OpenWrite11050
23Rewind23400
24Rowid2700
25NotExists13370
26Column1080
27Column1190
28Column12100
29Integer111100
30Column14120
31MakeRecord8515BBBDB0
32Insert11570
33Next22400
34DropTable000notes0
35SetCookie0120
36Halt0000
37Transaction01101
38String8030notes0
39String8040trigger0
40Goto0100

Open it in the EXPLAIN visualizer →

Also in this program: Column, Delete, DropTable, Eq, Goto, Halt, IfNot, Init, Insert, Integer, MakeRecord, Ne, Next, NotExists, Null, OpenEphemeral, OpenRead, OpenWrite, Rewind, Rowid, SetCookie, String8, Transaction.

What the SQLite documentation says

Delete an entire database table or index whose root page in the database file is given by P1.

The table being destroyed is in the main database file if P3==0. If P3==1 then the table to be destroyed is in the auxiliary database file that is used to store tables create using CREATE TEMPORARY TABLE.

If AUTOVACUUM is enabled then it is possible that another root page might be moved into the newly deleted root page in order to keep all root pages contiguous at the beginning of the database. The former value of the root page that moved - its value before the move occurred - is stored in register P2. If no page movement was required (because the table being dropped was already the last one in the database) then a zero is stored in register P2. If AUTOVACUUM is disabled then a zero is stored in register P2.

This opcode throws an error if there are any active reader VMs when it is invoked. This is done to avoid the difficulty associated with updating existing cursors when a root page is moved in an AUTOVACUUM database. This error is thrown even if the database is not an AUTOVACUUM db in order to avoid introducing an incompatibility between autovacuum and non-autovacuum modes.

See also: Clear

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.

← Delete · Divide →