The DELETE statement deletes rows in a table.
Syntax
<delete_statement> ::=
DELETE [FROM] <table_name> [<reference_name>] [KEY <key_spec>,...] [WHERE <search_condition>]
| DELETE [FROM] <table_name> [<reference_name>] WHERE CURRENT OF <result_table_name>
Explanation
The table name must denote an existing base table, view table (see
Table), or a synonym.The current user must have the DELETE privilege for the specified table. If the table name identifies a view table, even the owner of the view table may not have the DELETE privilege because the view table cannot be changed.
Table name identifies a view table: the rows of the tables on which the view tables are based are deleted.
Table name identifies a join view table: only the following rows are deleted:
The following specifications determine the rows in the table that are deleted:
CURRENT OF
If CURRENT OF is specified, the table name in the
FROM clause of the QUERY statement, with which the result table was built, must be identical to the table name in the DELETE statement.If CURRENT OF is specified and the cursor is positioned on a row in the result table, the corresponding row is deleted. The corresponding row is the row of the table specified in the FROM clause of the query statement, from which the result table row was formed. This procedure requires that the result table was specified with FOR UPDATE. Afterwards, the cursor is positioned behind the result table row. It is impossible to predict whether or not the updated values in the corresponding row are visible the next time the same row of the result table is accessed.
DELETE rule
For each row deleted in the course of the delete statement which originates from a referenced table of at least one
referential CONSTRAINT definition, one of the following actions is carried out - depending on the DELETE rule of the referential constraint definition:Trigger
If
triggers that are to be executed after a DELETE statement were defined for base tables from which rows are to be deleted with the DELETE statement, they are executed accordingly. The DELETE statement will fail if one of these triggers fails.Further information
In the case of the DELETE statement, the third entry of SQLERRD in the SQLCA is set to the number of deleted rows. If this counter has the value -1, either a significant part of the table or the entire table was deleted by the delete statement.
If errors occur in the course of the delete statement, the statement fails, leaving the table unchanged.