Partager via


Working with Table Indexes

When you create a table, Visual FoxPro creates a table (.dbf) file and, if your table includes memo or general fields, the associated table memo (.fpt) file. By default, Visual FoxPro stores records in the table in the order that you enter them. When your application performs operations on the table, the records are processed in the order they were entered.

You can control the order and increase the speed of processing table records by creating an index for the table. An index does not change the physical order of the records stored in the table; rather, it provides an efficient and versatile mechanism for accessing table records. For example, suppose you want to process records in a customer table by company name in alphabetical order. You can create a table index based on the company name field so that your application can process records in the order specified by the index you created. You can also add a filter to the index so you can add only those records that meet the filter criteria to the index.

After you create the table index, you can set the order of records in the table to the index so that your application processes records in the order specified. In addition, you can create different indexes for a table so that you can change the order in which your application processes records. For example, you might want to organize a customer table by contact name to quickly find the name you want or by postal code to generate mailing labels that are presorted for efficient mailing. You can create and store different ordering scenarios for tables by creating multiple indexes for the same table. You can use different types of index files to store indexes depending on their frequency of use.

You can also use indexes to create persistent relationships between tables in a database, making it possible for you to access the exact records you want. Persistent relationships between database tables are stored in the database file and exist as the default relationships when you use the tables in the data environment.

In This Section

Reference

  • Working with Data
    Describes how to design and build your database to create effective applications with indexes, tables, and databases based on your data requirements.

  • Working with Tables (Visual FoxPro)
    Discusses how to make sure your tables have the structure that your application requires.

  • Working with Fields
    Introduces records, how to view them, and how to use them to store data in tables.