Delete information from a table

You can delete data from a table by using the SQL DELETE statement. You can delete entire rows from a table when they no longer contain needed information or you can use the WHERE clause with the DELETE statement to identify rows to be deleted during a single statement execution.

To remove all the rows in a table that have the null value for the QUANTITY_ON_HAND column, follow these steps:

  1. Enter the following statement on the Enter SQL Statements display:
    DELETE
    	FROM SAMPLECOLL.INVENTORY_LIST
    	WHERE QUANTITY_ON_HAND IS NULL
    To check a column for the null value, the IS NULL comparison is used.

    This disclaimer information pertains to code examples.

  2. After the delete operation is completed, run another SELECT statement. This results in the following table:
                                     Display Data
                                                 Data width . . . . . . :      71
    Position to line  . . . . .              Shift to column  . . . . . .
    ....+....1....+....2....+....3....+....4....+....5....+....6....+....7.
    ITEM    ITEM                        UNIT   QUANTITY  LAST      NUMBER
    NUMBER  NAME                        COST   ON        ORDER     ORDERED
                                               HAND      DATE
    153047  Pencils, red               10.00        25   -              20
    229740  Lined tablets               1.50       120   -              20
    303476  Paper clips                 2.00       100   05/30/94       50
    559343  Envelopes, legal            3.00       500   -              20
    775298  Chairs, secretary         225.00         6   -              20
    073956  Pens, black                20.00        25   -              20
    ********  End of data  ********
                                                                           Bottom
    F3=Exit      F12=Cancel      F19=Left      F20=Right      F21=Split
The rows with a null value for QUANTITY_ON_HAND were deleted.