14
MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Embed Size (px)

Citation preview

Page 1: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

MS Access: Creating Relational Databases

Instructor: Vicki Weidler

Assistant: Joaquin Obieta

Page 2: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Overview

• Normalize tables to reduce data redundancy • Understand the requirements for first,

second, and third normal forms • Set one-to-one, one-to-many, and many-to-

many relationships between tables • Implement referential integrity between

related tables • Use cascading deletes and updates to

prevent orphan records

Page 3: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Normalization

The process of restructuring data files to:

• reduce data to its simplest structure • minimize redundancy• achieve the most efficient and functional yet

flexible way to store data

Page 4: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

First Normal Form (1NF)

Eliminates duplicate data…• a table should not contain similar information in several fields;

eliminate duplicative columns from the same table or move repeating fields to a related table

• a table should not contain fields that can be further broken down into smaller meaningful parts

• create separate tables for each group or related data and identify each row with a unique column (the primary key); each table should describe a single entity (object) class

Definition1NF

Page 5: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Second Normal Form (2NF)

Requires all data in the table apply directly to the subject of the table indicated by the primary key field…• if the table has a single-field primary key and meets the requirements for

1NF, then it also meets the requirements for 2NF• however, if the table has a composite (multiple-field) primary key, then all

the fields in the table must be related to and/or dependent on ALL the fields of the composite primary key

• to convert a table to 2NF, find all the fields that are related to only part of the composite (multiple-field) primary key, group these fields into another table, then assign a primary key to the new table

• another way of looking at it is to remove ALL subsets of duplicate/redundant data that apply to multiple rows of a table and place them in new tables, then create relationships between these new tables and the original tables by using foreign keys Definition

2NF

Page 6: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Third Normal Form (3NF)

Eliminates fields that can be derived from other fields…• if a table contains fields that do not relate to

and are not fully dependent on the primary key and completely describe the object that table represents, then it is not in 3NF

• to convert a table to 3NF, delete all the fields that do not relate to the primary key

Definition 3NF

Page 7: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Fourth Normal Form (4NF)

Requires that tables not contain fields for two or more independent, multi-varied facts…• this rule requires splitting tables that consist

of lists of independent attributes• i.e. in a relation table, job skills and language

fluency are independent facts about an employee; therefore, the 3-field relation table must be split into 2 two-field relation tables

Page 8: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Fifth Normal Form (5NF)

Requires the capability to reconstruct the source data from the tables that have met 1NF, 2NF, 3NF and 4NF…

• you should be able to regenerate from the database a spreadsheet that contains all the data in the original version

• this is an “acid test” for normalization and requires considerable skill in designing queries to join related tables to produce a readable output to compare wit the original data

Page 9: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Relating Tables

Relationships used to extract data from several tables at the same time

Primary key unique identifier for each record in a table

Foreign key the primary key in the related table

Page 10: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Types of Relationships

One-to-One Relationship

When one complete record in the primary table is related to just one record in the related table and vice versa; both tables are equally dependent on each other

One-to-Many Relationship

When one record in the primary table is related to several records in the related table; however, a record in the related table has only one related record in the primary table

Many-to-Many Relationship

When several records in one table are related to several records in another table. A many-to-many relationship cannot be created directly in MS Access. To relate such tables, you must first create a junction table that contains the primary keys of both tables

Page 11: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Referential Integrity

Referential Integrity

Ensures that changes made to one table will be reflected in the related table

Orphan Records

When a record is deleted in the primary table without deleting the related records in the other table

Page 12: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Referential Integrity Cont.

Cascading Deletes

When you delete a record from the primary table, cascading deletes automatically deletes all related records from other related tables; this ensures that there are no orphan records

Cascading Updates

When you change a primary key in a table, the change is updated in all of the related tables

Page 13: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

Summary

• Normalize tables to reduce data redundancy • Understand the requirements for first,

second, and third normal forms • Set one-to-one, one-to-many, and many-to-

many relationships between tables • Implement referential integrity between

related tables • Use cascading deletes and updates to

prevent orphan records

Page 14: MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta

•Resources•Questions & Answers•Evaluations•Thank You!!!

Conclusion