English 中文(简体)
MS Access - Indexing
  • 时间:2024-12-22

MS Access - Indexing


Previous Page Next Page  

An index is a data structure, a special data structure designed to improve the speed of data retrieval. If you often search a table or sort its records by a particular field, you can speed up these operations by creating an index for the field. Microsoft Access uses indexes in a table as you use an index in a book to find data.

    In some instances, such as for a primary key, Access automatically creates an index for you.

    At other times, you might want to create an index yourself.

    An index stores the location of records based on the field or fields that you choose to index.

    After Access obtains the location from the index, it can then retrieve the data by moving directly to the correct location.

    In this way, using an index can be considerably faster than scanning through all of the records to find the data.

    Indexes can speed up searches in queries, but they can also slow down performance when adding or updating records.

Let us now look into what indexes Microsoft Access creates by default and how to create them ourselves and learn how to delete any unnecessary indexes. Open the tblEmployees table in Access database which we have created.

    We haven t really played with indexes in this database but that doesn t mean we don t have any.

    In fact, any field that is set as a primary key in Access is automatically indexed.

    Access creates additional secondary indexes depending on the names of your fields.

Let us now go to the File menu and select Options.

File Menu

You will see the Access Options window.

Object Designer

Go to the Object Designers and you will see a section labeled AutoIndex on Import/Create and in the textbox you will see ID;key;code;num. By default, access automatically adds a secondary index to fields that start or end with these names and that goes for fields you have imported as well as ones you have manually created.

If you want to make any field indexed you can go to the Field tab.

Indexed

Select any field that you want indexed and check the Indexed checkbox in Field Vapdation section. You also have alternate options for creating or removing an index. You can go back to the Design View.

Design View

You can adjust indexes by selecting any field. You can also see how they are indexed in the field properties area below. Any field that has No selected next to indexed, means there is no index for that given field. You can change that by cpcking on the drop-down menu and choosing the other two options — Yes (Duppcate OK) and Yes (No duppcates).

Compression

The last option Yes (No Duppcates) means that Access will automatically prohibit duppcate values in that field. Let us now create an index for our last name field.

Duppcate

Let us select LastName to index and say Yes (Duppcates OK). As we save, Access will create that index. Another area where you can view and adjust your indexes for a table is the tables design area in the Show/Hide group.

Duppcate Yes

If you cpck on this Indexes button that will bring up a special view displaying all the indexes created for this table.

Special View

We now have two indexes for tblEmployees —one that was created automatically based on the primary key field and one that we just created for the LastName field. These are the different ways to deal with indexes in Microsoft Access tables.

Advertisements