4. Determining Relationships Planning is most important Break down fields into tables to avoid redundancies Clients table Client # Client Street Address City State Zip Code Insurance table License # Client # Insurance Code Uninsured Motorist Coverage table Insurance Code Type of Insurance Claims table Claim # Client # License # Date of Claim Amount of Claim Notice that each table is about only one subject Some fields appear in more than one table – they are used to create a relationship
5.
6. Creating a Primary Field…/2 Open table in Design view Position insertion point in field Click Primary Key button Notice image of key To define more than one field as the primary key, select the rows and click the Primary Key button
7. Creating a Foreign Key A primary key field in one table may be a foreign key in another Primary key and foreign key form a relationship between the tables Clients table Client # Client Street Address City State Zip Code Insurance table License # Client # Insurance Code Uninsured Motorist Coverage table Insurance Code Type of Insurance Claims table Claim # Client # License # Date of Claim Amount of Claim
8.
9. Creating a One-to-Many Relationship Open database file Click Database Tools tab, Relationships Show Table dialog box appears when no relationships have been defined yet
10. Creating a One-to-Many Relationship…/2 Double-click each table to add it to the Relationships window After adding all the tables Repeat until all required tables are added Click Close when done adding Notice that the Primary keys are indicated
11. Creating a One-to-Many Relationship…/3 Drag the common field from the primary table (the “one”) to the related table (the “many”) Edit Relationships dialog box appears Ensure that the correct tables and field names display Make sure type is One-To-Many Click Check options as desired
12. Creating a One-to-Many Relationship…/4 Join line is thick at both ends if referential integrity option has been chosen Save the Relationship by clicking the Save button in the Quick Access toolbar Join line This join line shows that each client may have many claims (1 to ∞)
13. Specifying Referential Integrity If a related table contains a record, you will not be able to change or delete a primary key value in the primary table As you change a primary key value in the primary table, Access will automatically update the matching value in the related tables As you delete a record in the primary table, Access will also delete any related records in the related tables
14. Printing Database Relationships With the Relationships open, click the Relationship Report button The Relationships report in Print Preview Click the Print button in Quick Access toolbar
15. Creating Additional Relationships Open Relationships if necessary and click the Show Table button to add other tables to the database relationships Drag a primary key in one table to a foreign key in another table Follow the same procedure as before to verify the table fields and the relationship type, and to set the desired referential integrity
16. Editing a Relationship Right-click a join line and click Edit Relationship OR Can move a table entry by dragging its Title bar Open Relationships … Click a join line and click OR Double-click a join line
17. Deleting a Relationship Open Relationships … Right-click a join line and click Delete OR Click a join line and press the Delete key
18. Showing a Subdatasheet Click + sign preceding desired record + expands - collapses Select table Click OK
19. Displaying Related Records in a Subdatasheet Can view, edit or add data in the subdatasheet Click + sign preceding desired record + expands - collapses Only available when tables have relationships
20. Managing Subdatasheets Can choose a different subdatasheet With an open table … Click Home tab, More button (in the Records group) Can remove the subdatasheet Same as clicking the + or – preceding each record of the table
21. Features Summary How do you identify a primary key? Image of a key shows by the field name
22. Features Summary How do you display the Relationships window? Database Tools tab, Relationships button
23. Features Summary How do you display the Edit Relationships dialog box? Right-click a join line and click Edit Relationship OR Click a join line and click OR Double-click a join line
24. Features Summary How do you display the Show Table dialog box? Database Tools tab, Relationships, click the Show Table button
25. Features Summary How do you print database relationships? With the Relationships open, click the Relationship Report button Click the Print button in Quick Access toolbar
26. Features Summary How do you display the Insert Subdatasheet dialog box? Features Summary Click the + sign preceding a record Click Home tab, Records group, More button, Click Open a table OR