Microsoft Office Tutorials and References
In Depth Information
Tutorial B: Microsoft Access Tutorial
end of the year. Thus, Employee ID values will not distinguish records. No other single field can distinguish
these records either, because other employees will have worked during the same week number and some
employees will have worked the same number of hours. For example, 40 hours
which corresponds to a
would be a common entry for many weeks.
All of this presents a problem because a table must have a primary key field in Access. The solution is to
use a compound primary key; that is, use values from more than one field to create a combined field that will
distinguish records. The best compound key to use for the current example consists of the Employee ID field
and the Week # field, because as each person works each week, the week number changes. In other words,
there is only one combination of Employee ID 08965 and Week # 1. Because those values can occur in only
one record, the combination distinguishes that record from all others.
The first step of setting a compound key is to highlight the fields in the key. Those fields must appear one
after the other in the table definition screen. (Plan ahead for that format.) As an alternative, you can highlight
one field, hold down the Control key, and highlight the next field.
AT THE KEYBOARD
In the Hours Worked table, click the first field’s left prefix area (known as the row selector), hold down the
mouse button, and drag down to highlight the names of all fields in the compound primary key. Your screen
should resemble the one shown in Figure B-5.
Selecting fields for the compound primary key for the Hours Worked table
Now click the Key icon. Your screen should resemble the one shown in Figure B-6.
The compound primary key for the Hours Worked table
You have created the compound primary key and finished defining the table. Click the File tab and then
select Save Object As to save the table as Hours Worked.
Adding Records to a Table
At this point, you have set up the skeletons of three tables. The tables have no data records yet. If you printed
the tables now, you would only see column headings (the field names). The most direct way to enter data into
a table is to double-click the table
s name in the navigation pane at the left side of the screen and then type
the data directly into the cells.
To display and open the database objects, Access 2010 uses a navigation pane, which is on the left side of the Access