Microsoft Office Access 2007: Intermediate Course 01 Relational Databases
Slide 1 Relational Databases Course objectives Normalize tables Set relationships between tables Implement referential integrity
Slide 2 Topic A Topic A: Database Normalization Topic B: Relating Tables Topic C: Implementing Referential Integrity
Slide 3 Normalization Normalized tables are Low maintenance because they don t have duplicate data Flexible, enabling querying with ease Adaptable, absorbing business changes without requiring extensive design modification
Slide 4 Steps to Normalize Rule 1 Take small bites and no repeating Will you need to sort, group by, or print a subset of the information in the field? If so, break it up Do you see the same kind of information in more than one field? Will you need to add more fields in the future? If so, move this information to another table in one tall field
Slide 5 Steps to Normalize Rule 2 Stay on topic Each non-key field must relate to the entire multiple-field primary key Does data in the multiple-field primary key indicate the value of the non-key field? If so, move that non-key field to another table Does the value in the non-key field correspond directly to the values in the multiple-field primary key? If not, move that non-key field to another table
Slide 6 Steps to Normalize Rule 3 Stay on topic Each non-key field must relate to the entire single-field primary key Is data in this non-key field a fact about the primary key? If not, move that non-key field to another table Could we have more than one non-key field for a single primary key? If so, move the non-key field to another table
Slide 7 Topic B Topic A: Database Normalization Topic B: Relating Tables Topic C: Implementing Referential Integrity
Slide 8 Establishing Relationships 1. Click the Relationships button 2. Click Show Table 3. Select the desired table and click Add 4. Click Close 5. In the Relationships window, drag the desired field from the first table to the desired field in the second table 6. Click Join Type 7. Select the desired properties option 8. Check Enforce Referential Integrity and click Create
Slide 9 Relationships Window
Slide 10 One-to-Many Relationship Two tables have a one-to-many relationship when one record in the primary table relates to several records in the related table
Slide 11 Junction Tables Used to create a many-to-many relationship Act as a link between two tables Contain primary key fields of both tables to be related
Slide 12 Many-to-Many with Junction
Slide 13 Printing Table Relationships 1. In the Design tab, click Relationship Report. The report opens in Print Preview mode 2. Right-click the report tab and choose Design view 3. Make any necessary changes to the header, detail, or footer of the report, and save your changes 4. Right-click the report tab and choose Print Preview. Verify the appearance of the report 5. On the Print Preview tab, click Print
Slide 14 Topic C Topic A: Database Normalization Topic B: Relating Tables Topic C: Implementing Referential Integrity
Slide 15 Referential Integrity The primary table must have a primary key The related fields should be of same data type The tables must belong to the same database
Slide 16 Orphan Records Records in a table that have no related records in the primary table Result from deleting records in the primary table without deleting the related records in the related table
Slide 17 Cascading Deletes 1. Open the Relationships window 2. Double-click the line between tables 3. Check Enforce Referential Integrity 4. Check Cascade Delete Related Records 5. Click OK
Slide 18 Test Cascading Deletes 1. Open the desired table 2. Navigate to the record to be deleted 3. Press Delete 4. Click Yes to delete the record 5. Update and close the table 6. Open a related table to confirm that all related records have been deleted
Slide 19 Cascading Updates Ensure that any changes made to the primary key in the primary table are reflected in the related tables Can be set by checking Cascade Update Related Records in the Edit Relationships dialog box
Slide 20 Course Summary Normalized tables to reduce data redundancy Set relationships between tables Implemented referential integrity between related tables
Review Questions: 1. What is the first rule of data normalization? A. Each non-key field must relate to the whole multiple-field primary key B. Each non-key field must relate to the single-field primary key C. Fields should contain the smallest meaningful value, and there should be no repeating groups of fields D. None of the above 2. Table relationships are based on matching fields. When the matching field is the in a table, that table is known as the related table. A. Foreign Key B. Main table C. Access Key D. Primary Key 3. True or False: In a related table, only one field can be linked to a field in another table. A. True B. False 4. True or False: To establish a table relationship, the first step is to go to the Database Tools tab and click Relationships. A. True B. False 5. What is the purpose of creating a junction table? A. Create a one-to-one relationship B. Create a one-to-many relationship C. Create a many-to-many relationship D. All of the above 6. What is/are the requirement(s) that must be satisfied before referential integrity can be implemented? A. The primary table has a primary key B. The related fields are the same data type C. The tables belong to the same database D. All of the above
Answer Key: 1. C Fields should contain the smallest meaningful value, and there should be no repeating groups of fields. 2. A Table relationships are based on matching fields. When the matching field is the foreign key in a table, that table is known as the related table. 3. B False. In a related table, one or more fields can be linked to fields in another table. The link ensures that you can enter only those values that have corresponding entries in the other table. A relational database is in the form of related tables. 4. A True. To establish a table relationship, the first step is to go to the Database Tools tab and click Relationships. 5. C The purpose of a junction table is to create a many-to-many relationship between Access tables. 6. D All three are requirements that must be satisfied before referential integrity can be implemented.