Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 39

Before you begin

If a yellow security bar appears at the top of the


screen in PowerPoint, click Enable Editing.

You need PowerPoint 2010 to view this presentation. If


you don’t have PowerPoint 2010,
download the PowerPoint Viewer (see the URL in the
notes pane).
® ®
Microsoft Access 2010 Training

Create relationships
for a new database
Course contents
• Overview: Relationships are essential
• Lesson: Includes eight sections
• Suggested practice tasks
• Test
• Quick Reference Card

Create relationships for a new database


Overview: Relationships are essential
Learn how to create table relationships
for a new Access 2010 database.
Relationships are essential because they
bring the data in your tables together
so you can extract meaningful
information.

This course explains the different types


of relationships and shows you how to
create them. This is the third course in a
series that teaches beginners how to
use Access 2010.

Create relationships for a new database


Course goals
• Create a one-to-many relationship.
• Set referential integrity.
• Create lookup fields.
• Create a one-to-one relationship.
• Create a many-to-many relationship.

Create relationships for a new database


Create relationships
Let’s do a quick review.
The first course in this
series showed you how
to divide your data into
separate tables and
identify the relationships
between those tables. In
the second course, you
built your tables and
gave each one a primary
key – a field with a value
Primary and foreign keys in a table structure. that makes each row
unique.
Now it’s time to link
your tables by creating
relationships.

Create relationships for a new database


Create relationships
In a database,
relationships are critical
because they’re how
your tables “talk” to
each other. If your tables
don’t talk, you can’t get
answers from your data.
You create relationships
by using a field from
one table as a field in a
related table.
Primary and foreign keys in a table structure.

Create relationships for a new database


Create relationships
1 The field you include is
your primary key. Each of
the tables in your
database has a primary
key, and you include it as
a new field in another
table to create a
relationship with that
other table.
2 When you share a
primary key, the new
field in the second table
Primary and foreign keys in a table structure. is called a foreign key.

Create relationships for a new database


Create relationships
3 The picture illustrates
one way this can work. In
order to associate assets
with suppliers, the
foreign key field in the
Assets table provides a
list of company names.
Behind the scenes,
Access uses the values in
the primary and foreign
keys to synchronize the
two fields.
Primary and foreign keys in a table structure. In turn, you can use that
relationship to answer
questions such as,
“Which company
provided a given
computer?”

Create relationships for a new database


Create relationships
This course shows you
how to create that type
of relationship and how
to set rules that control
how you can update
and delete the data in
your database.

Primary and foreign keys in a table structure.

Create relationships for a new database


Types of relationships
Your tables can
participate in three
types of relationships, as
shown in the picture:

1 You have a one-to-one


relationship when a
single record in one
table is related to a
single record in another
table, and vice versa.
2 You have a one-to-
The three types of table relationships: one-to-one, many relationship when
one-to-many; and many-to-many. one record in a table is
related to many records
in another table.

Create relationships for a new database


Types of relationships
3 You have a many-to-
many relationship when
several records in one
table are related to
several records in
another table.

The three types of table relationships: one-to-one,


one-to-many; and many-to-many.

Create relationships for a new database


Types of relationships
This course shows you
how to create all three
types, but we’ll spend
most of our time on
one-to-many
relationships because
they’re the most
common.
Also, if you want to
publish a database to
SharePoint, then you
The three types of table relationships: one-to-one, have to create lookup
one-to-many; and many-to-many. fields, and a video later
in this course shows you
how.

Create relationships for a new database


Relationships have “sides”
At this point, it helps to
think of relationships
has having “sides.”
For example, one
supplier can provide
many assets, so the
Suppliers table resides
on the “one” side of the
relationship, while the
Assets table sits on the
“many” side, as the
The Suppliers table resides on the “one” side, and the picture shows.
Assets table sits on the “many” side.

Create relationships for a new database


Relationships have “sides”
Next, remember this
rule: To create a one-to-
many relationship, you
use the primary key
from the table on the
“one” side as a foreign
key in the table on the
“many” side. You’ll see
how to do that next.

The Suppliers table resides on the “one” side, and the


Assets table sits on the “many” side.

Create relationships for a new database


Create relationships

Point to the bottom of the video to see the video controls. Drag or point
along the progress bar to move forward or go back.

Create relationships for a new database


Set referential integrity

Point to the bottom of the video to see the video controls. Drag or point
along the progress bar to move forward or go back.

Create relationships for a new database


Create lookup fields

Point to the bottom of the video to see the video controls. Drag or point
along the progress bar to move forward or go back.

Create relationships for a new database


Create a one-to-one relationship
You may not use one-
to-one relationships
often, but you should
know how to create
them. You start by
creating a one-to-many
relationship, and then
you change the
indexing.
Access uses indexing in
the same way that you
The process for creating a one-to-one relationship. use an index in a book:
to find information
quickly. When you
create a primary key,
Access automatically
indexes that field, which
makes searches faster.

Create relationships for a new database


Create a one-to-one relationship
In a one-to-many
relationship, the primary
key has indexing turned
on, but the foreign key
field has indexing
turned off. In a one-to-
one relationship, both
key fields have indexing
turned on, and neither
field allows duplicate
values.
The process for creating a one-to-one relationship. You can use Design
View or the ribbon to
turn on indexing for
your foreign key fields.
We’ll show you how to
use Design View here.

Create relationships for a new database


Create a one-to-one relationship
1 In the Navigation Pane,
right-click the table that
contains the foreign key
field, then click Design
View.
2 In the designer, click the
foreign key field.
3 Under Field Properties,
on the General tab, click
the list next to Indexed
and select Yes (No
Duplicates).
The process for creating a one-to-one relationship.
Save your changes —
and there you go.

Create relationships for a new database


Create a many-to-many relationship
You have a many-to-
many relationship when
a single record in one
table can relate to many
records in another, and
a single record in that
second table can also
relate to many records
in the first.

The tables in a many-to-many relationship.

Create relationships for a new database


Create a many-to-many relationship
For example, say your
company has several
types of computers and
several technicians, with
each technician certified
to work on some, but
not all, of the
computers.
Each technician can be
related to more than
one computer, and in
The tables in a many-to-many relationship. turn, each computer can
be related to more than
one technician.

Create relationships for a new database


Create a many-to-many relationship
To track who can work
on a given machine, you
create a many-to-many
relationship by adding
the primary keys from
both sides of the
relationship to a third
table, called a junction
or link table.
In other words, a many-
to-many relationship is
The tables in a many-to-many relationship. really just a pair of one-
to-many relationships.

Create relationships for a new database


Create a many-to-many relationship
The picture shows a
typical many-to-many
relationship. You can see
it has a relatively simple
structure — a junction
table with a pair of
foreign keys and some
related fields.
You use the data in that
junction table to answer
questions such as,
The tables in a many-to-many relationship. “Which computers did a
given technician work
on last month?”

Create relationships for a new database


Suggestions for practice
1. Create a relationship by using the Relationships Pane.
2. Set referential integrity and cascading changes.
3. Create a relationship for a Web database.
4. Create a one-to-one relationship.
5. Create a many-to-many relationship.

Online practice (requires Access 2010)

Create relationships for a new database


Test question 1
It’s a good idea to think of relationships as having “sides.”
(Pick one answer.)

1. True.
2. False.

Create relationships for a new database


Test question 1
It’s a good idea to think of relationships as having “sides.”

Answer:
1. True.

Knowing which side a table is on tells you whether or not it


uses a foreign key field.

Create relationships for a new database


Test question 2
To create one-to-many relationships, you do which of the
following? (Pick one answer.)

1. Use the primary key from the table on the “one” side as
a foreign key in the table on the “many” side.
2. Use a junction table with at least two foreign key fields.
3. Turn off indexing for the primary key field.

Create relationships for a new database


Test question 2
To create one-to-many relationships, you do which of the
following?

Answer:
1. Use the primary key from the table on the “one” side as a
foreign key in the table on the “many” side.

In the asset-tracking database, you can now answer


questions such as, “Which company supplies most of our
computers?”

Create relationships for a new database


Test question 3
To create a one-to-one relationship, you do which of the
following? (Pick one answer.)

1. Turn off indexing for the foreign key field.


2. Turn on indexing in the foreign key field, but allow
duplicate values.
3. Turn on indexing for the foreign key field without
allowing duplicate values.
4. Enable referential integrity.

Create relationships for a new database


Test question 3
To create a one-to-one relationship, you do which of the
following?

Answer:
3. Turn on indexing for the foreign key field without allowing
duplicate values.

If you allow duplicate values, you create a one-to-many


relationship.

Create relationships for a new database


Test question 4
Referential integrity is useful because it does which of the
following? (Pick one answer.)

1. Takes the place of an index.


2. Keeps primary and foreign key values in synch.
3. Allows you to “orphan” data safely.

Create relationships for a new database


Test question 4
Referential integrity is useful because it does which of the
following?

Answer:
2. Keeps primary and foreign key values in synch.

Referential integrity can also make it easy to update and


delete data.

Create relationships for a new database


Test question 5
To create a many-to-many relationship between Table A and
Table B, you do which of the following? (Pick one answer.)

1. Create one-to-one relationships between A, B, and at


least two other tables.
2. Add the primary keys from A and B to a “link” or
“junction” table.
3. Add as many fields as needed from table A to table B,
and vice versa, until each table contains all the data you
need to track.

Create relationships for a new database


Test question 5
To create a many-to-many relationship between Table A and
Table B, you do which of the following?

Answer:
2. Add the primary keys from A and B to a “link” or “junction”
table.

Those foreign keys allow you to see how the data on each
side relate to each other.

Create relationships for a new database


Test question 6
This course has taught you everything you need to know
about relationships. (Pick one answer.)

1. True.
2. False.

Create relationships for a new database


Test question 6
This course has taught you everything you need to know
about relationships.

Answer:
2. False.

The pointers in the Quick Reference Card take you to a lot


more information. There’s a link on the next slide; grab it.

Create relationships for a new database


Quick Reference Card
For a summary of the tasks covered in this course, view the
Quick Reference Card.

Create relationships for a new database

You might also like