Database Basics - Indexes

 

An index consists of a set of one or more columns.  By defining indexes you improve database performance by making it faster to find and sort the information stored in a table.  Indexes can also be used to enforce constraints or rules about the type of data that a table can store.  

 

How do I set up an index?

Unique Indexes

When you define an index as unique, you ensure that each record in the table will have a unique set of values for the indexed columns.

Primary Indexes

A primary index (also called a primary key) is similar to a unique index, except that each table can have only one primary key.  The values stored in the primary key columns uniquely identify each row in the table.  Most databases do not allow primary key columns to contain null values.

 

Often, primary keys consist of a single autonumber field (often called an identity).  The values in autonumber fields are system-generated numbers which are always unique.

 

Primary keys are necessary in order to create a relationship, called a foreign key, between tables.

 

Tell me more about foreign keys.

Clustered Indexes

A clustered index defines the order in which the data should be stored in the database.  This means that there can only be one clustered index per table.

 

Related Topics: