Access07 l1 ch2

1,724 views

Published on

0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,724
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
126
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Access07 l1 ch2

  1. 1. CREATING RELATIONSHIPS BETWEEN DATABASE TABLES Chapter 2 Microsoft Access 2007 – Level 1
  2. 2. Performance Objectives <ul><li>Create a database table with a primary key </li></ul><ul><li>Create a database table with a foreign key </li></ul><ul><li>Create a relationship between database tables </li></ul><ul><li>Print table relationships </li></ul><ul><li>Display Subdatasheets </li></ul>
  3. 3. Creating Related Tables <ul><li>Access is a relational database management system </li></ul><ul><li>Relationships are defined between sets of data (tables) </li></ul><ul><ul><li>allows greater flexibility in manipulating data </li></ul></ul><ul><ul><li>eliminates redundancy </li></ul></ul>
  4. 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. 5. Creating a Primary Field <ul><li>Need to designate a primary (key) field in a table before creating a relationship between tables </li></ul><ul><li>Must contain unique data </li></ul><ul><li>Access enforces Entity Integrity </li></ul><ul><ul><li>expects a value in the primary field in each record </li></ul></ul><ul><ul><li>cannot close a table containing a null value in a primary (key) field </li></ul></ul>
  6. 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. 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. 8. Establishing a Relationship <ul><li>Relate one table to another by join ing the tables </li></ul><ul><ul><li>data can be extracted from both tables </li></ul></ul><ul><li>Define the type of relationship to be created </li></ul><ul><ul><li>one record in the primary table will match zero, one, or many records in the related table (one-to-one, or one-to-many) </li></ul></ul><ul><li>Set Referential Integrity </li></ul><ul><ul><li>a record must be added to the “one” table before it can be added to the “many” table </li></ul></ul>
  9. 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. 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. 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. 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. 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. 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. 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. 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. 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. 18. Showing a Subdatasheet Click + sign preceding desired record + expands - collapses Select table Click OK
  19. 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. 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. 21. Features Summary How do you identify a primary key? Image of a key shows by the field name
  22. 22. Features Summary How do you display the Relationships window? Database Tools tab, Relationships button
  23. 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. 24. Features Summary How do you display the Show Table dialog box? Database Tools tab, Relationships, click the Show Table button
  25. 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. 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
  27. 27. Coming Next MODIFYING AND MANAGING TABLES Chapter 3

×