Partager via


SET KEY Command

Specifies access to a range of records based on their index keys.

SET KEY TO [eExpression1 | RANGE eExpression2 [, eExpression3]]
   [IN cTableAlias | nWorkArea]

Parameters

  • eExpression1
    Allows access to a set of records with identical index keys. eExpression1 is a single index key value. All records with index keys that match eExpression1 are accessible.

  • RANGE eExpression2 [, eExpression3]
    Allows access to a set of records with index keys that fall within a range of index key values. eExpression2 allows access to records with index keys equal to or greater than eExpression2. eExpression3 (preceded by a comma) allows access to records with index keys equal to or less than eExpression3. Including both eExpression2 and eExpression3 (separated by a comma) allows access to records with index keys equal to or greater than eExpression2 and equal to or less than the eExpression3.

    For example, the CUSTOMER table includes a character field containing postal codes. If the table is indexed on the postal code field, you can specify a range of postal codes with SET KEY.

    In the following example, only records with postal codes falling within the range of 40000 to 43999 appear in a Browse window:

    CLOSE DATABASES
    USE customer
    SET ORDER TO postalcode
    SET KEY TO RANGE '40000', '43999'
    BROWSE
    
  • IN cTableAlias | nWorkArea
    Allows access to a range of records for a table open in a specific work area. cTableAlias specifies the work area alias and nWorkArea specifies the work area number. If no table has the alias you specify, Visual FoxPro generates an error message. If you omit the work area alias and number, SET KEY operates on the table in the currently selected work area.

Remarks

Use SET KEY to limit the range of records you can access in a table. The table must be indexed, and the index key value or values you include must be the same data type as the index expression of the master index file or master tag.

Issue SET KEY TO without any additional arguments to restore access to all records in the table.

See Also

INDEX | KEY( ) | SET FILTER