Share via


DELETE Command

Marks records for deletion.

DELETE [Scope] [FOR lExpression1] [WHILE lExpression2]
   [IN nWorkArea | cTableAlias] [NOOPTIMIZE]

Parameters

  • Scope
    Specifies a range of records to mark for deletion. The default scope for DELETE is the current record (NEXT 1). The scope clauses are: ALL, NEXT nRecords, RECORD nRecordNumber, and REST.

    For more information on scope clauses, see Scope Clauses.

  • FOR lExpression1
    Specifies a condition whereby only the records that satisfy the logical condition lExpression1 are marked for deletion.

    Rushmore Query Optimization optimizes a query created with DELETE ... FOR if lExpression1 is an optimizable expression and the table is indexed on DELETED( ). For best performance, use an optimizable expression in the FOR clause.

    For information on Rushmore optimizable expressions, see SET OPTIMIZE, and Using Rushmore Query Optimization to Speed Data Access in Optimizing Applications, .

  • WHILE lExpression2
    Specifies a condition whereby records are marked for deletion for as long as lExpression2 evaluates to true (.T.).

  • IN nWorkArea
    Specifies the work area of the table in which records are marked for deletion.

  • IN cTableAlias
    Specifies the alias of the table in which records are marked for deletion.

    If you omit nWorkArea and cTableAlias, records are marked for deletion in the table in the currently selected work area.

  • NOOPTIMIZE
    Disables Rushmore optimization of DELETE.

Remarks

Records marked for deletion aren't physically removed from the table until PACK is issued. Records marked for deletion can be recalled (unmarked) with RECALL.

Example

The following example opens the customer table in the testdata database. DELETE is used to mark all records for deletion where the country field contains USA. All the records marked for deletion are displayed. RECALL ALL is used to unmark all the records marked for deletion.

CLOSE DATABASES
OPEN DATABASE (HOME(2) + 'Data\testdata')
USE customer  && Opens Customer table

DELETE FOR country = 'USA'  && Mark for deletion
CLEAR
LIST FIELDS company, country FOR DELETED( ) && List marked records
RECALL ALL  && Unmark all records marked for deletion

See Also

DELETE - SQL | DELETED( ) | PACK | RECALL | SET DELETED