How to: Enhance the Efficiency of Indexes

You can improve the performance of indexed tables by keeping indexes current and using expressions that can be optimized in your indexes. You can rebuild active index files or reindex tables at run time.

Rebuilding Active Index Files

When you open a table without opening its corresponding index files and make changes to the key fields in the table, index files become outdated. Index files can also become invalid when a system crash occurs or potentially by accessing and updating a table from a program other than Visual FoxPro. When index files become outdated, you can update them by reindexing with the REINDEX command.

To rebuild an active index file

  1. Open the table you want to reindex.

  2. On the Table menu, choose Rebuild Indexes.

To rebuild active index files programmatically

  • Use the REINDEX command to rebuild an index.

    REINDEX updates all index files open in the selected work area. Visual FoxPro recognizes and reindexes each index file type accordingly.

    For example, the following code updates the index file for the Customer table in the Visual FoxPro sample database, TestData:

     CopyCode imageCopy Code
    OPEN DATABASE (HOME(2) + 'Data\TestData')
    USE Customer

For more information, see REINDEX Command.


Reindexing tables at run time can take time, particularly when you're reindexing large tables. You should reindex tables only when necessary. You can enhance performance by reindexing during the initialization or termination portion of your program, rather than performing indexing maintenance during the main portion of an application.

See Also

© , 1996-2020 • Updated: 11/10/20
Comment or report problem with topic