0% found this document useful (0 votes)
4 views

MS-Access-Relating-Data

The document explains database normalization, which organizes data in relational databases to reduce redundancy and improve performance. It details the types of relationships between tables: one-to-many, many-to-many, and one-to-one, and emphasizes the importance of defining these relationships in MS Access to facilitate data management. Additionally, it outlines the process of creating relationships in MS Access, including the use of foreign keys and junction tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

MS-Access-Relating-Data

The document explains database normalization, which organizes data in relational databases to reduce redundancy and improve performance. It details the types of relationships between tables: one-to-many, many-to-many, and one-to-one, and emphasizes the importance of defining these relationships in MS Access to facilitate data management. Additionally, it outlines the process of creating relationships in MS Access, including the use of foreign keys and junction tables.
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

MS Access -

Relating Data
Normalization

Database normalization, or simply normalization, is the process


of organizing columns (attributes) and tables (relations) of a
relational database to minimize data redundancy. It is the
process of splitting data across multiple tables to improve
overall performance, integrity and longevity.
•Normalization is the process of organizing data in a database.
•This includes creating tables and establishing relationships
between those tables according to rules designed both to
protect the data and to make the database more flexible by
eliminating redundancy and inconsistent dependency.
Let us now look into the following table which contains data, but the problem
is that this data is quite redundant which increases the chances of typo and
inconsistent phrasing during data entry.
To solve this problem, we need to restructure our data and break it down into multiple
tables to eliminate some of those redundancy as shown in the following three tables.

Here, we have one table for Customers, the 2nd one is for Orders and the 3rd one is for
Cookies.
The problem here is that just by splitting the data in multiple tables will not help to
tell how data from one table relates to data in another table. To connect data in
multiple tables, we have to add foreign keys to the Orders table
Defining Relationships
A relationship works by matching data in key columns
usually columns with the same name in both the
tables. In most cases, the relationship matches the
primary key from one table, which provides a unique
identifier for each row, with an entry in the foreign key
in the other table. There are three types of
relationships between tables. The type of relationship
that is created depends on how the related columns
are defined.
THREE TYPES OF
RELATIONSHIPS
One-to-Many Relationships
A one-to-many relationship is the most common type of
relationship. In this type of relationship, a row in table A
can have many matching rows in table B, but a row in
table B can have only one matching row in table A.
For example, the Customers and Orders tables have a
one-to-many relationship: each customer can place
many orders, but each order comes from only one
customer.
Many-to-Many Relationships
In a many-to-many relationship, a row in table A can have
many matching rows in table B, and vice versa.
You create such a relationship by defining a third table,
called a junction table, whose primary key consists of the
foreign keys from both table A and table B.
For example, the Customers table and the Cookies table
have a many-to-many relationship that is defined by a one-
to-many relationship from each of these tables to the
Orders table.
One-to-One Relationships
In a one-to-one relationship, a row in table A can
have no more than one matching row in table B,
and vice versa. A one-to-one relationship is
created if both the related columns are primary
keys or have unique constraints.
This type of relationship is not common because most
information related in this way would be all in one table.
You might use a one-to-one relationship to −
•Divide a table into many columns.
•Isolate part of a table for security reasons.
•Store data that is short-lived and could be easily deleted
by simply deleting the table.
•Store information that applies only to a subset of the
main table.
MS Access - Create
Relationships
In this chapter, we will understand the need to create
relationships between related tables. One of the goals of good
database design is to remove data redundancy.
•To achieve that goal, you divide your data into many subject-
based tables so that each fact is represented only once.
•To do this, all the common fields which are related to each other
are placed in one table.
•To do this step correctly, you must first understand the
relationship between your tables, and then specify these
relationships in your Access database.
Why Create Table Relationships?

MS Access uses table relationships to join tables when you need to use them in a database
object. There are several reasons why you should create table relationships before you
create other database objects, such as forms, queries, macros, and reports.
• To work with records from more than one table, you often must create a query that joins the
tables.
• The query works by matching the values in the primary key field of the first table with a
foreign key field in the second table.
• When you design a form or report, MS Access uses the information it gathers from the table
relationships you have already defined to present you with informed choices and to
prepopulate property settings with appropriate default values.
• When you design a database, you divide your information into tables, each of which has a
primary key and then add foreign keys to related tables that reference those primary keys.
• These foreign key-primary key pairings form the basis for table relationships and multi-
table queries.
MS Access - One-To-One
Relationship
Let us now understand One-to-One
Relationship in MS Access. This
relationship is used to relate one
record from one table to one and
only one record in another table.
Let us now go to the Database
Tools tab.

Click on the Relationships option.


Select tblEmployees and tblHRData a
nd then click on the Add button to add
them to our view and then close
the Show Table dialog box.

To create a relationship between these


two tables, use the mouse, and click and
hold the EmployeeID field
from tblEmployees and drag and drop
that field on the field we want to relate
by hovering the mouse right
over EmployeeID from tblHRData.
When you release your mouse button,
Access will then open the following
window
The above window relates EmployeeID of
tblEmployees to EmployeeID of
tblHRData. Let us now click on
the Create button and now these two
tables are related.

The relationship is now saved


automatically and there's no real need to
click on the Save button. Now that we
have the most basic of relationships
created, let us now go to the table side
to see what has happened with this
relationship.
Let us open
the tblEmployees table.
Here, on the left-hand side of each
and every record, you will see a
little plus sign by default. When you
create a relationship, Access will
automatically add a sub-datasheet
to that table.

Let us click on the plus sign and you


will see the information that is
related to this record is on
the tblHRData table.
Click on the Save icon
and
open tblHRData and
you will see that the
data we have entered is
already here.
MS Access - One-To-Many
Relationship
The vast majority of your
relationships will more
than likely be this one to
many relationships where
one record from a table
has the potential to be
related to many records in
another table.
The process to create one-
to-many relationship is
exactly the same as for
creating a one-to-one
relationship
MS Access - Many-To-Many
Relationship
To represent a many-to many
relationship, you must create a
third table, often called a
junction table, that breaks
down the many-to-many
relationship into two one-to-
many relationships. To do so,
we also need to add a junction
table. Let us first add another
table tblAuthers.
Let us now create a many-to-
many relationship. We have
more than one author working on
more than one project and vice
versa. As you know, we have an
Author field in tblProjects so, we
have created a table for it. We do
not need this field any more.

Select the Author field and press


the delete button and you will see
the following message.
We will now have to create a
junction table. This junction table
have two foreign keys in it as shown
in the following screenshot.
These foreign key fields will be the
primary keys from the two tables
that were linked together
— tblAuthers and tblProjects.
To create a composite key in Access,
select both these fields and from
the table tools design tab, you can
click directly on that primary key
and that will mark not one but both
of these fields.
The combination of these two
fields is the tables’ unique
identifier. Let us now save
this table
as tblAuthorJunction.
The last step in bringing the
many-to-many relationships
together is to go back to
that relationships view and
create those relationships by
clicking on Show Table.
Select the above three
highlighted tables and click
on the Add button and then
close this dialog box.
The relationship you’re creating is
the one that Access will consider
as a one-to-many relationship.
We will also enforce referential
integrity. Let us now turn
on Cascade Update and click on
the Create button as in the
above screenshot.
Let us now hold the ProjectID,
drag and drop it right on top
of ProjectID from tblAuthorJun
ction.
END

You might also like