Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Identifying Relationships

Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

What Will I Learn?


Objectives
In this lesson, you will learn to:
Interpret and describe relationship optionality
Interpret and describe relationship cardinality
Relate entities by applying the rules of cardinality and
optionality

Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

Why Learn It?


Purpose
Being able to identify the relationships between entities makes
it easier to understand the connections between different
pieces of data.
It helps you see how different parts of a system affect each
other. For example, the entities STUDENT and COURSE are
related to each other.
To accurately model the business, the relationships are as
important as the entities themselves.

Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

Tell Me / Show Me
Relationships in Families
What is the relationship between you and your aunt, you and
your uncle, your cousins, your grandmother, etc? What would a
society be like that did not categorize relatives as aunts, uncles,
cousins, grandmothers and grandfathers but only by their name?
How could you tell someone that Jenny was your cousin?
It would be a long and potentially confusing introduction, like
This is Jenny, who is the child of the woman who has the same
parents as my parent who is a woman, as opposed to This is
Jenny, my mothers sisters child, or This is Jenny, my aunts
child, or the simplest one This is Jenny, my cousin.

Notice that we still use a basic relationship in the longest


introduction -- that of child to parent. Without that relationship it
would be very difficult to introduce anyone beyond giving their
name!
Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

Tell Me / Show Me
Relationships in Data Models
Relationships:
Represent something of significance/importance to the
business
Show how entities are related to each other
Always exist between two entities (or one entity twice)
Always have two sides
Are named at both ends
Have an optionality
Have a degree or cardinality

Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

Tell Me / Show Me
What is Optionality in a Relationship?
Relationships are either mandatory or optional. Based on what you
know about instances of the entities, you can determine optionality
by answering four questions:
Must every employee have a job? In other words, is this a
mandatory or optional relationship for an employee?
Can employees have more than one job?
Must every job be done by an employee? (In other words, is this
a mandatory or optional relationship for a job?)
Can each job be done by more than one employee?

Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

Tell Me / Show Me
What is Cardinality in a Relationship?
Cardinality of a relationship determines the degree of a
relationship. It answers how many.

For example:

How many jobs does an employee hold? One or more? Just


one?
A job may be held by how many employees? Just one? One or
more?

Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

Tell Me / Show Me
Optionality and Cardinality
Examples:
Each EMPLOYEE must hold one and only one JOB
Each JOB may be held by one or more EMPLOYEEs

Each PRODUCT must be classified by one and only one


PRODUCT TYPE
Each PRODUCT TYPE may classify one or more
PRODUCTs

Copyright 2011, Oracle. All rights reserved.

Identifying Relationships

Tell Me / Show Me
Relationships

Each SEAT may be sold to one


or more PASSENGERs

Each PASSENGER may


purchase one SEAT

SEAT is sold to a PASSENGER


(or PASSENGERs -- hence,
overbooking)

PASSENGER purchases or
books a SEAT

Copyright 2011, Oracle. All rights reserved.

SEAT

PASSENGER

Identifying Relationships

Tell Me / Show Me
Business Scenario 1
What are the relationships in the
following business scenario?
We like to classify all our music, each
song or soundtrack, by type. The
different types are rock, jazz, country,
classical, pop, new age, etc. We can
add new types as the need arises. In
fact, we recently added a new type for
rap music. We realize that a song can
really be classified under more than one
type, but for our purposes we select
only one main classification type for
each song."

RELATIONSHIP

SONG
(music/soundtrack) is
classified by TYPE

TYPE is a classification
for SONG

Copyright 2011, Oracle. All rights reserved.

10

Identifying Relationships

Tell Me / Show Me
Business Scenario 1
(continued)
SONG has a TYPE: optionality
and cardinality

SONG
Stairway to Heaven

TYPE

Optionality = Must or may?

Green Dolphin Street

Each SONG must be classified


by one (and only one) TYPE.
Each TYPE may be a
classification for one or more
SONGs.

rock
jazz
new age

classical
pop

Minute Waltz
Pachelbel Canon
Thriller
Stand By Your Man

country

Cardinality = How many?


Each SONG must be classified
by one (and only one) TYPE.
Each TYPE may be a
classification for one or more
SONGs.

Copyright 2011, Oracle. All rights reserved.

11

Identifying Relationships

Tell Me / Show Me
SONG

Business Scenario 1
(continued)

TYPE

Green Dolphin Street

SONG has a TYPE


What if there is no TYPE for
a SONG?

Stairway to Heaven

rock
jazz
new age

classical
pop

country

Do the business rules state


that every SONG has a
TYPE? If yes, then an
additional TYPE needs to be
added.

Copyright 2011, Oracle. All rights reserved.

Minute Waltz
Pachelbel Canon
Thriller
Stand By Your Man

Amazing
Grace

12

Identifying Relationships

Tell Me / Show Me
SONG

Business Scenario 1
(continued)
TYPE

SONG has a TYPE

Stairway to Heaven
Green Dolphin Street

rock

Can you have a TYPE with


no SONG?

jazz
new age

classical
pop

Why would you have a


TYPE with no SONG?

Minute Waltz
Pachelbel Canon
Thriller
Stand By Your Man

country

Copyright 2011, Oracle. All rights reserved.

13

Identifying Relationships

Tell Me / Show Me
Business Scenario 1
(continued)
SONG has a TYPE

SONG

TYPE

How many TYPEs can a


SONG belong to?

Business rules determine


cardinality.
If a SONG can belong to
more than one TYPE the
cardinality would be stated
as:

Stairway to Heaven
Green Dolphin Street

rock
jazz
new age

classical

pop

Minute Waltz
Pachelbel Canon
Thriller
Stand By Your Man

country

Each SONG must be


classified by one or more
TYPEs.
Copyright 2011, Oracle. All rights reserved.

14

Identifying Relationships

Tell Me / Show Me
Business Scenario 2
What are the relationships in the
following business scenario?

In our restaurant, customers come up


to the counter and place their orders. A
customer can order for himself/herself
or for a whole group of people. For
example, if a mother orders for herself
and her children, we consider that
mother to be the customer who owns
the order and who is responsible for
payment. Of course, the customer can
place as many orders as he/she wants.

RELATIONSHIP

CUSTOMER places
ORDERS
An ORDER is placed
by one CUSTOMER

Copyright 2011, Oracle. All rights reserved.

15

Identifying Relationships

Tell Me / Show Me
CUSTOMER

Business Scenario 2
(continued)

Linda

CUSTOMER has ORDERs:


optionality and cardinality

Krishna
Mel

Optionality = Must or may?

Each ORDER must be placed by


one (and only one) CUSTOMER.
Each CUSTOMER must place
one or more ORDERs.

Cardinality = How many?


Each ORDER must be placed by
one (and only one) CUSTOMER.
Each CUSTOMER must place
one or more ORDERs.

ORDER
Order No. 100
-French fries
- Large soda
Order No. 102
- Apple pie

Order No. 77
-Hamburger
- Salad
- Fruit cup

Order No. 10
-Vegetarian platter
- Orange juice

Copyright 2011, Oracle. All rights reserved.

16

Identifying Relationships

Tell Me / Show Me
Business Scenario 3
A relationship can relate an
entity to itself. Examine the
following scenario.
We need to keep track of our
employees and their
managers. Every employee
has one manager, including
the managing director, who
manages him/herself. Each
manager can manage several
employees.
Since managers are also
employees, there is only one
entity here: EMPLOYEE.

RELATIONSHIP
An EMPLOYEE manages EMPLOYEEs
An EMPLOYEE is managed by one EMPLOYEE

Copyright 2011, Oracle. All rights reserved.

17

Identifying Relationships

Tell Me / Show Me
Terminology
Key terms used in this lesson include:
Cardinality/Degree
Relationship
Optionality

Copyright 2011, Oracle. All rights reserved.

18

Identifying Relationships

Summary
Objectives Summarized
In this lesson, you have learned how to:
Interpret and describe relationship optionality
Interpret and describe relationship cardinality
Relate entities by applying the rules of cardinality and
optionality

Copyright 2011, Oracle. All rights reserved.

19

Identifying Relationships

Summary
Practice Guide
The link for the lesson practice guide can be found in the
course resources in Section 0.

Copyright 2011, Oracle. All rights reserved.

20

You might also like