Compartilhar via


REINDEX Command

Rebuilds open index files.

REINDEX updates all index files open in the selected work area.

REINDEX [COMPACT]

Parameters

  • COMPACT
    Converts regular single index (.idx) files to compact .idx files.

Remarks

Index files become outdated when you open a table without opening its corresponding index files and make changes to the index files' key fields. When index files become outdated, you can update them by reindexing.

Visual FoxPro recognizes each index file type: compound index (.cdx) files, structural .cdx files, and single index (.idx) files), and reindexes them accordingly. It updates all tags in .cdx files and updates structural .cdx files, which automatically open with the table.

Tip   To speed network traffic during a REINDEX operation, you can use SYS(3050) - Set Buffer Memory Size to set buffer memory to a size large enough to store the entire table. During the first pass, the table is paged locally, and later passes will not attempt to read paged data from the remote computer.

Any index files created with the UNIQUE keyword of the INDEX command or with SET UNIQUE ON retain their UNIQUE status when reindexed.

To REINDEX outdated index files, issue these commands:

USE TableName INDEX OutdatedIndexNames
REINDEX

Example

In the following example, ISEXCLUSIVE( ) verifies that the customer table was opened for exclusive use. The table is not reindexed since the one in the current work area was not opened for exclusive use.

cExclusive = SET('EXCLUSIVE')
SET EXCLUSIVE OFF
SET PATH TO (HOME(2) + 'Data\')
OPEN DATA testdata  && Opens the test databsase
USE Customer     && Not opened exclusively
USE Employee IN 0 EXCLUSIVE    && Opened exclusively in another work area

IF ISEXCLUSIVE( )
 REINDEX  && Can only be done if table opened exclusively
ELSE
  WAIT WINDOW 'The table has to be exclusively opened'
ENDIF

SET EXCLUSIVE &cExclusive

See Also

INDEX | SET INDEX | SET EXCLUSIVE | SET UNIQUE | SYS( ) Functions Overview | USE