Delete Statement (deleteStatement)
Purpose
Deletes data from a table of a data container.
Syntax
%%{init: {
'theme': 'base',
'flowchart': { 'padding': '7', 'nodeSpacing': '20', 'rankSpacing': '20' },
'themeVariables': {
'fontSize': '11px',
'fontFamily': 'Arial'
}
}}%%
flowchart TD
deleteStatement_start((START))
deleteStatement_start --> deleteStatement_0_0[DELETE]:::quoted
deleteStatement_0_0 --> deleteStatement_0_2
deleteStatement_0_0 --> deleteStatement_0_1[<a href="https://documentation.invantive.com/Invantive UniversalSQL/Execution Hints/Execution Hints" class="internal-link">executionHints</a>]
deleteStatement_0_1 --> deleteStatement_0_2[FROM]:::quoted
deleteStatement_0_2 --> deleteStatement_0_3[tableSpec]
deleteStatement_0_2 --> deleteStatement_0_4
deleteStatement_0_3 --> deleteStatement_0_4[whereClause]
deleteStatement_0_3 --> deleteStatement_0_5
deleteStatement_0_4 --> deleteStatement_0_5[limitClause]
deleteStatement_0_5 --> deleteStatement_end((END))
Where the Rows Are Deleted
The platform of the table deletes the rows itself, with one statement, when it can delete by a condition and when every condition of the where clause can be handed to it. That is the case for Microsoft SQL Server, Oracle, PostgreSQL, MySQL and the other SQL databases, and for some cloud platforms such as Exact Online.
Otherwise the engine retrieves the rows, evaluates the where clause itself and deletes the qualifying rows one by one by their primary key. A table without a primary key that the engine knows is then refused with itgendid086, before any row is deleted. The engine takes this route when:
- a condition cannot be handed to the platform, such as
upper(name) = 'X'or a comparison with a calculation such asprice * 2 > 10, also when it is part of anoror of anot; - the statement has a
limitclause.
A not over a comparison is handed to the platform as the opposite comparison, so not (status = 'C') is handed to it as status <> 'C'.
For example, delete from orders where (status = 'C' and upper(reference) = 'X') or year = 2020 deletes row by row, because upper(reference) is evaluated by the engine. Up to and including release 27.0, such a statement was handed to the platform as status = 'C' or year = 2020 and could delete more rows than it asks for.