Rebuild open indexes in the current work area
Syntax
REINDEX [EVAL <lCondition>] [EVERY <nRecords>]
Arguments
EVAL <lCondition> specifies a condition that is evaluated either for each record processed or at the interval specified by the EVERY clause. This clause is identical to the EVAL clause of the INDEX command, but must be respecified in order for the reindexing operation to be monitored since the value of <lCondition> is transient.
EVERY <nRecords> specifies a numeric expression that modifies how often EVAL is evaluated. When using EVAL, the EVERY option offers a performance enhancement by evaluating the condition for every nth record instead of evaluating each record reindexed. The EVERY keyword is ignored if no EVAL condition is specified.
Description
REINDEX is a database command that rebuilds all open indexes in the current work area. When the reindexing operation finishes, all rebuilt indexes remain open, order is reset to one, and the record pointer is positioned to the first record in the controlling index. If any of the indexes were created with SET UNIQUE ON, REINDEX adds only unique keys to the index. If any of the indexes were created using a FOR condition, only those key values from records matching the condition are added to the index.
In a network environment, REINDEX requires EXCLUSIVE USE of the current database file. Refer to the “Network Programming” chapter for more information.
Caution! REINDEX does not recreate the header of the index file when it recreates the index. Because of this, REINDEX does not help if there is corruption of the file header. To guarantee a valid index, always use INDEX ON in place of REINDEX to rebuild damaged indexes
Notes
Index key order, UNIQUE status, and the FOR condition are known to the index (.ntx) file and are, therefore, respected and maintained by REINDEX.
Examples
. This example REINDEXes the index open in the current work area: USE Sales INDEX Salesman, Territory NEW REINDEX . This example REINDEXes using a progress indicator: USE Sales INDEX Salesman, Territory NEW REINDEX EVAL NtxProgress() EVERY 10 FUNCTION NtxProgress LOCAL cComplete := LTRIM(STR((RECNO()/LASTREC()) * 100)) @ 23, 00 SAY "Indexing..." + cComplete + "%" RETURN .T.
Seealso
INDEX, PACK, SET INDEX, USE