Lesson 10 | Understanding the primary key |
Objective | Choose and define a primary key field. |
Understanding primary key
The primary key is the field in the table that uniquely identifies each record. But
why should you have one, and how is it used? The primary key is one (or more) field that uniquely identifies every record in a table. A primary key is an index of the table. Like the tables you have seen created in this module, many tables will have an AutoNumber field as their primary key. However, there may be times when
you want another field to be the primary key. For instance, it may make sense to use a social security number field as a primary key.
Once you designate a field as the primary key, you cannot enter duplicate data in this field. This prevents data entry mistakes.
The primary key is often used in relationships between tables, In addition, it can provide a shortcut when entering data in related tables. For instance, rather than repeating a customer name in the Projects table, I can simply use the primary key, the Customer ID.
Defining the Primary Key
There are two ways to define a primary key, you can let Access create an AutoNumber field and define it as the primary key for you, or you can create your table and then select the field to be the primary key. You have already used the first method in the previous module,
remember? This simulation takes you through the second method--you have already defined the fields in the table, and now you want to define the primary key.
Table Primary Key
- The SSN field is going to be the primary key for this table. The first step is to select the field by clicking the gray selection box to the left of the field.
- The field is now selected. If you were creating a multiple field key you would now select any additional fields by holding down the Shift key while clicking the selection box for the additional fields. To define the selected key as the primary key click the Primary Key button on the toolbar, it is in the middle, and looks like a key.
- The key symbol in the selection box indicates that the field is the primary key for the table. When the field is selected in Design view the Primary Key button on the toolbar is depressed. If you need to remove the primary key from the table, you can select the primary key field(s) and click the Primary Key button on the toolbar and it disappears.
- This is the end of the simulation. To close this window and return to your lesson, click on the End Simulation button.
Move on to the module wrap-up!
Brush up on the key terms and concepts you have encountered in this module, and take a quiz.
Primary Key - Exercise