Microsoft Office Tutorials and References
In Depth Information
Specifying the Primary Key
The ﬁ fth, and ﬁ nal, ﬁ eld to be deﬁ ned in the Invoice table is InvoicePaid. This ﬁ eld
will be a Yes/No ﬁ eld to indicate the payment status of each invoice record stored in the
Invoice table. Recall that the Yes/No data type is used to deﬁ ne ﬁ elds that store true/false,
yes/no, and on/off ﬁ eld values. When you create a Yes/No ﬁ eld in a table, the default
Format property is set to True/False. After setting the data type, you’ll set the Format
property for the InvoicePaid ﬁ eld to Yes/No.
To define the InvoicePaid field:
1. Click the fifth row’s Field Name box, type InvoicePaid , and then press the Tab
key to advance to the Data Type box.
2. Type y. Access completes the data type as “yes/No.”
3. Press the Tab key to select the Yes/No data type and move to the Description box.
4. Click the Format box, click the arrow on its right side, and then click Yes/No to
set the Format property.
5. Press the Tab key to move to the Caption box, and then type Invoice Paid .
You’ve ﬁ nished deﬁ ning the ﬁ elds for the Invoice table. Next, you need to specify the
primary key for the table.
Specifying the Primary Key
As you learned in Tutorial 1, the primary key for a table uniquely identiﬁ es each record
in a table.
Understanding the Importance of the Primary Key
Although Access does not require a table to have a primary key, including a primary key
offers several advantages:
• A primary key uniquely identifies each record in a table.
• Access does not allow duplicate values in the primary key field. For example, if a
record already exists in the Contract table with a ContractNum value of 3020, Access
prevents you from adding another record with this same value in the ContractNum
field. Preventing duplicate values ensures the uniqueness of the primary key field.
• When a primary key has been specified, Access forces you to enter a value for the
primary key field in every record in the table. This is known as entity integrity . If you do
not enter a value for a field, you have actually given the field a null value . You cannot
give a null value to the primary key field because entity integrity prevents Access from
accepting and processing that record.
• Access stores records on disk as you enter them. You can enter records in any order,
but Access displays them by default in order by the field values of the primary key. If
you enter records in no specific order, you are ensured that you will later be able to
work with them in a more meaningful, primary key sequence.
• Access responds faster to your requests for specific records based on the primary key.