Professional Documents
Culture Documents
9-3
Relationship Mapping
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 3
Relationship Mapping
Purpose
• Suppose that you are building a house for someone.
• You have all of the materials – wood, paint, doors, windows,
nails, screws, etc. – and the skills, but you do not have a
design.
• As you start, you don’t know how many rooms should be
included, where the windows should be placed, how the
doors should be oriented, or what color each room should be
painted.
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 4
Relationship Mapping
Purpose
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 5
Relationship Mapping
Purpose
• Relationships are mapped between primary keys and foreign
keys to allow one table to reference another.
• If we don’t map relationships, we just have a lot of
standalone tables containing information that does not
connect to anything else in the database.
• Mapping relationships between entities serves as a critical
“first-step” to facilitate discussion between the customer,
designer, developer, and administrator of the database
product.
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 6
Relationship Mapping
Rules for Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 7
Relationship Mapping
Rules for Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 8
Relationship Mapping
Rules for Relationships Illustrated
managed by
EMPLOYEE DEPARTMENT
# id # id
the manager belong to
* name * name
of * address composed of
* birth date
EMPLOYEES (EPE)
DEPARTMENTS (DPT)
Key Type Optionality Column
Name Key Type Optionality Column
Name
pk * id
pk * id
* name
uk * name
* address
* birth_date
foreign key refers to
fk1 * dpt_id
fk2 o mgr_id
foreign key refers to
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 9
Relationship Mapping
Mapping of Mandatory Relationship at the
One Side
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 10
Relationship Mapping
Mapping of Mandatory Relationship at the
One Side
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 11
Relationship Mapping
Enforcing Optionality
MUSICIAN BAND
# id a member of
# id
* name composed of * name
o instrument
MUSICIANS (MSN)
BANDS (BAD)
Key type Optionality Column
name foreign Key type Optionality Column
pk * id key name
* name refers pk * id
to * name
o instrument
fk o bad_id
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12
Relationship Mapping
Mapping of Nontransferable Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 13
Relationship Mapping
Enforcing Nontransferable Relationships
PAY CHECK EMPLOYEE
# id issued to # id
* pay period * name
the recipient
of
PAYCHECKS (PCK)
fk * epe_id
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 14
Relationship Mapping
Mapping of Barred Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 15
Relationship Mapping
Mapping of Barred Relationships
ACCOUNT located in
BANK
# number # number
* balance the location * name
* date opened of
ACCOUNTS (ACT)
Key Type Optionality Column Name
pk * act_nbr
* balance
* date_opened
pk,fk * bak_nbr
BANKS (BAK)
refers
to
Key Type Optionality Column Name
pk * bank_number
* name
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 16
Relationship Mapping
Cascade Barred Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 17
Relationship Mapping
Cascade Barred Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 18
Relationship Mapping
Cascade Barred Relationships
ROOM located within SUITE located within FLOOR located within BUILDING
# number # number # number # id
the location the location
o tenant the location * address
of of of
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 19
Relationship Mapping
Cascade Barred Relationship Illustrated
2 201 1 15 2 100
2 15 2 100
1 7B 2 201
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 20
Relationship Mapping
Mapping Many-to-Many Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 21
Relationship Mapping
Mapping Many-to-Many Relationships
REVIEW
* rating
CRITIC MOVIE
# id # id
* name * title
CRITICS (CTC)
pk * id REVIEWS (RVW)
* name Key Type Optionality Column Name
pk, fk1 * ctc_id
MOVIES (MVE) pk, fk2 * mve_id
pk * id * rating
* title
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 22
Relationship Mapping
Mapping One-to-One Relationships
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 23
Relationship Mapping
Mapping One-to-One Relationships
EMPLOYEE CUBILCLE
# id allocated # code
* first_name * description
* last_name allocated to
…..
* name * description
fk, uk * cbe_code
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 24
Relationship Mapping
Optional One-to-One
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 25
Relationship Mapping
Optional One-to-One
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 26
Relationship Mapping
Business Rules for Optional One-to-One
CAR SPACE
# license plate parked in # id
* model * description
the location
for
Car-Rental Business
* model * description
fk, uk o spe_id
Parking-Lot Business
fk, uk o car_lic_plate
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 27
Relationship Mapping
Enforcing One-to-Many
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 28
Relationship Mapping
Mapping Arcs
• The entity that has the arc will map to a table that contains
foreign keys from the tables on the “one” end of the
relationships.
• Note that even if the relationships in the arc are mandatory
on the many side, the resulting foreign keys have to be
optional (because one of them will always be blank).
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 29
Relationship Mapping
Mapping Arcs
COMPANY
MEMBERSHIP held by
# id
# id * name
* Start date the holder of * Contact name
* Expiration date
O Termination
held by CUSTOMER
# id
the holder of
* First name
* Last name
COMPANIES (CPE)
MEMBERSHIPS (MBP) pk * id
pk * id * name
* start_date
* contact _name
* expiration_date
CUSTOMERS (CMS)
o termination
pk * id
fk1 o cpe_id
fk2 o cms_id * first_name
* last_name
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 30
Relationship Mapping
Mapping Arcs
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 31
Relationship Mapping
Terminology
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 32
Relationship Mapping
Summary
DDS9L3 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 33
Relationship Mapping