How to: Set Controlling Indexes

A table can have many index files open simultaneously; however, only one master, or controlling, index file or tag specifies the order in which Visual FoxPro displays or accesses the table. Also, certain commands, such as the SEEK command, use the controlling index file or tag to search for records.

Note

You cannot select binary indexes as controlling indexes. Visual FoxPro does not support the SET ORDER command when setting to a binary index tag. If you attempt to set order to a binary tag, Visual FoxPro generates an error, and the current order remains at its prior setting. Records in the table are displayed and accessed in record number order and not in an indexed order. Therefore, Visual FoxPro does not support SEEK operations for binary indexes.

After you create one or more indexes for a table, you need to assign a controlling index for organizing records in your table. You can designate an index tag in a compound index (.cdx) file or a standalone index (.idx) file as the controlling index tag or file. When changes are made to the table, all open .idx and .cdx files are updated.

You can select a controlling index using the Visual FoxPro IDE or language.

To designate a controlling index

  1. Open the browse window for your table.

  2. On the Table menu, choose Properties.

  3. In the Index order box of the Work Area Properties dialog box, select the index you want to use.

  4. Choose OK.

The browse window displays records in the order that the index specifies.

To set controlling indexes programmatically

  • Choose one of the following:

    • To set the controlling index for a table, use the SET ORDER command.

      Tip

      When opening a table using the USE command, including the ORDER clause in performs the same function as SET ORDER.

      You do not need to use SET ORDER for running queries.

    • To set the controlling index for the currently open table, use the SET INDEX command.

      Tip

      When opening a table using the USE command, including the INDEX clause in performs the same function as SET INDEX.

For example, suppose an index with the tag name Country is created for the Customer table in the Visual FoxPro sample database, TestData. The following code uses the SET ORDER command to specify Country as the controlling index for displaying the records in the table when you open the table. The BROWSE command opens a browse window and displays the records by country name:

OPEN DATABASE (HOME(2) + 'Data\TestData')
SET ORDER TO Country
BROWSE

For more information, see SET ORDER Command, SET INDEX Command, USE Command, and BROWSE Command.

See Also

Tasks

How to: Create Indexes (Visual FoxPro)
How to: Select Indexes at Run Time
How to: Display Records in Descending Order

Other Resources

Working with Table Indexes