Condividi tramite


REINDEX Command

Rebuilds open index files.

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.

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

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