Creating Multiple Indexes

As you work with the records in your table, you'll discover the need for accessing table records in several different sequences. For example, you might want to order the customer table by contact to quickly find a name you're looking for, or by postal code to generate mailing labels that are presorted for more efficient mailing.

You can create and store many different ordering scenarios for your table by creating multiple index keys for the same table. This enables you to order table records at different times according to different purposes.

To create additional index keys for a table

For example, the following code creates two new index keys on the employee table: one on the last_name field and another on the country field:

USE employee
INDEX ON last_name TAG last_name
INDEX ON country TAG country

When you create an index tag without specifying the name of an index file, the tag is added automatically to the table's structural .cdx index file. The following diagram shows a .cdx index file with three index tags.

.cdx index contains multiple tags representing multiple record-ordering scenarios.

Two of the tags in the diagram, emp_id and last_name, represent indexes based on single fields. The cntry_last index orders records using a simple two-field index expression.

Controlling the Order in which Records Are Accessed

After you create index keys for the customer table on the company, city, and country fields, you can access and display the table in different orders, simply by choosing the index key you prefer. You use the SET ORDER Command to choose a specific index key as the ordering key for the table.

For example, the following code opens a Browse Window displaying the records in the customer table in order by country:

SET ORDER TO country
BROWSE

See Also

Permitting Duplicate Values | Setting Record Order at Run Time | Working with Records | Table Designer | INDEX Command | Using Other Index Types | Creating One Index | Ordering by Multiple Fields | Index Creation for Tables