This document covers the following topics:
Belongs to Function Group: Database Access and Update
The SQL DELETE statement is used to delete either rows
                            in a table without using a cursor ("searched"
                               DELETE) or rows in a table to which a cursor is
                            positioned ("positioned"
                               DELETE).
               
Two different structures are possible.
The "searched" DELETE statement is a
                            stand-alone statement not related to any SELECT statement. With a single
                            statement you can delete zero, one, multiple or all rows of a table. The rows
                            to be deleted are determined by a search-condition
                            that is applied to the table. Optionally, the table name can be assigned a
                            correlation-name.
               
Note:
 The number of rows that have actually been deleted with a
                               "searched" DELETE can be ascertained by using the
                               system variable *ROWCOUNT;
                               see System Variables documentation.
                  
Common Set Syntax:
| DELETEFROMtable-name
                                               [correlation-name]
                                               [WHEREsearch-condition] | 
Extended Set Syntax:
| DELETEFROMtable-name
                                               [correlation-name] | |||||||
| [ WHEREsearch-condition] | |||||||
| 
 | WITH | 
 | 
 | 
 | |||
For explanations of the symbols used in the syntax diagram, see Syntax Symbols.
Syntax Element Description:
| Syntax Element | Description | |
|---|---|---|
| FROM
                                                table-name |  FROM Clause: This clause specifies the table from which the rows are to be deleted. | |
| correlation-name | Correlation Name: Optional. The table name can be assigned a correlation-name. | |
| WHERE
                                                search-condition |  WHERE Clause: This clause is used to specify the selection criteria for the rows to be deleted. If no  | |
| WITH |  WITH Isolation Level
                                                     Clause: This clause belongs to the SQL Extended Set. This clause enables the explicit specification of the isolation level used when locating the row to be deleted. It is only valid against DB2 databases. When used against other databases, it will cause runtime errors. | |
| CS | Cursor Stability | |
| RR | Repeatable Read | |
| RS | Read Stability | |
The "positioned" DELETE statement always
                            refers to a cursor within a database loop. Therefore the table referenced by a
                            positioned DELETE statement must be the same as the one referenced
                            by the corresponding SELECT statement, otherwise an
                            error message is returned. A positioned DELETE cannot be used with
                            a non-cursor selection.
               
The functionality of the positioned DELETE statement
                            corresponds to that of the "native"
                               Natural DELETE statement.
               
| DELETE
                                                   FROMtable-nameWHERE
                                                   CURRENT OF CURSOR[(r)] | 
For explanations of the symbols used in the syntax diagram, see Syntax Symbols.
Syntax Element Description: