Creating a DELETE statement

Use a DELETE statement to remove data from your database table.

To create a DELETE statement using the SQL Builder:

  1. Switch to the Data Definition view in the Data perspective.

  2. Expand the project or folder that contains your database, and then expand the database nodes until you see the Statements folder.

  3. Right-click the Statements folder, and then click New > Delete Statement on the pop-up menu.

  4. Type a name for the statement, and then click OK. The SQL Builder opens.

  5. Add the table from which to delete data. Right-click in the Tables pane, and then click Add Table on the pop-up menu.

  6. In the Table name list, click the table to use.

  7. (Optional) Type an alias for the table.

  8. Click OK.

  9. (Optional) Add a condition to the DELETE statement that specifies which rows of the database to delete.

    1. In the Design pane, click the first row, and then click the cell under the Column heading.

    2. Click the column to include in the condition, or click Build Expression and build the expression to include in the condition.

    3. Click the adjoining cell under the Operator heading, and then click an operator in the list.

    4. Click the adjoining cell under the Value heading, and enter a value. You can specify a column, a specific value such as an integer or character string, or a host variable, or you can build an expression.

    5. When you are finished creating the condition, click outside of the row.

    6. Add further conditions, if needed. Select from the adjoining cell under the And/Or heading to specify how to evaluate the conditions. For example, if two conditions must both be true for a row to be deleted, click AND in the list for the first condition.
    Any row found in the specified database table that matches the condition is deleted. If you do not specify a condition, all rows of the target database table are deleted.

  10. After you have finished, click SQL > Execute.

The output is shown in the DB Output view.

To create a DELETE statement using the Create A New SQL Statement wizard:

  1. Click File > New > Other.

  2. In the New window, expand the Data folder, click SQL Statement, and then click Next.

  3. In the SQL statement field of the wizard, click DELETE.

  4. Fill in the remaining fields on the wizard pages, as necessary. To see information about a particular field, position the pointer in the field and then press F1.

DELETE statement
The DELETE statement is used to remove data from a specified database table or tables.

 

Parent topic

SELECT, UPDATE, INSERT and DELETE statements. The SQL Builder also supports WITH (DB2 only) and FULLSELECT statements. Any statement that you create is stored in a file with the extension .sqx.">Creating an SQL statement

 

Related tasks

Editing an SQL statement
Executing an SQL statement