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
| addr | opcode | p1 | p2 | p3 | p4 | p5 |
|---|---|---|---|---|---|---|
| 0 | Init | 0 | 37 | 0 | 0 | |
| 1 | Null | 0 | 1 | 0 | 0 | |
| 2 | OpenWrite | 0 | 1 | 0 | 5 | 0 |
| 3 | Rewind | 0 | 11 | 0 | 0 | |
| 4 | Column | 0 | 2 | 2 | 0 | |
| 5 | Ne | 3 | 10 | 2 | BINARY-8 | 82 |
| 6 | Column | 0 | 0 | 2 | 0 | |
| 7 | Eq | 4 | 10 | 2 | BINARY-8 | 82 |
| 8 | Rowid | 0 | 5 | 0 | 0 | |
| 9 | Delete | 0 | 0 | 0 | 2 | |
| 10 | Next | 0 | 4 | 0 | 1 | |
| 11 | Destroy | 11 | 2 | 0 | 0 | |
| 12 | Null | 0 | 6 | 7 | 0 | |
| 13 | OpenEphemeral | 2 | 0 | 6 | 0 | |
| 14 | IfNot | 2 | 22 | 1 | 0 | |
| 15 | OpenRead | 1 | 1 | 0 | 4 | 0 |
| 16 | Rewind | 1 | 22 | 0 | 0 | |
| 17 | Column | 1 | 3 | 13 | 0 | |
| 18 | Ne | 2 | 21 | 13 | BINARY-8 | 84 |
| 19 | Rowid | 1 | 7 | 0 | 0 | |
| 20 | Insert | 2 | 6 | 7 | 0 | |
| 21 | Next | 1 | 17 | 0 | 1 | |
| 22 | OpenWrite | 1 | 1 | 0 | 5 | 0 |
| 23 | Rewind | 2 | 34 | 0 | 0 | |
| 24 | Rowid | 2 | 7 | 0 | 0 | |
| 25 | NotExists | 1 | 33 | 7 | 0 | |
| 26 | Column | 1 | 0 | 8 | 0 | |
| 27 | Column | 1 | 1 | 9 | 0 | |
| 28 | Column | 1 | 2 | 10 | 0 | |
| 29 | Integer | 11 | 11 | 0 | 0 | |
| 30 | Column | 1 | 4 | 12 | 0 | |
| 31 | MakeRecord | 8 | 5 | 15 | BBBDB | 0 |
| 32 | Insert | 1 | 15 | 7 | 0 | |
| 33 | Next | 2 | 24 | 0 | 0 | |
| 34 | DropTable | 0 | 0 | 0 | notes | 0 |
| 35 | SetCookie | 0 | 1 | 2 | 0 | |
| 36 | Halt | 0 | 0 | 0 | 0 | |
| 37 | Transaction | 0 | 1 | 1 | 0 | 1 |
| 38 | String8 | 0 | 3 | 0 | notes | 0 |
| 39 | String8 | 0 | 4 | 0 | trigger | 0 |
| 40 | Goto | 0 | 1 | 0 | 0 |
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.