Mapping 3
Mapping 3
9-3
Relationship Mapping
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 3
Relationship Mapping
Purpose
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 4
Relationship Mapping
Purpose
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 5
Relationship Mapping
Purpose
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 6
Relationship Mapping
Rules for Relationships
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 7
Relationship Mapping
Rules for Relationships
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 8
Relationship Mapping
Rules for Relationships Illustrated
managed by
EMPLOYEE DEPARTMENT
# id # id
belong to
the manager * name * name
of * address
* birth date composed of
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 © 2015, Oracle and/or its affiliates. All rights reserved. 9
Relationship Mapping
Mapping of Mandatory Relationship at the
One Side
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 10
Relationship Mapping
Mapping of Mandatory Relationship at the
One Side
DDS9L3 Copyright © 2015, 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 Key type Optionality Column
pk * id foreign name
key
* name refers pk * id
to
o instrument * name
fk o bad_id
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 12
Relationship Mapping
Mapping of Nontransferable Relationships
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 13
Relationship Mapping
Enforcing Nontransferable Relationships
PAY CHECK EMPLOYEE
# id # id
issued to
* pay period * name
the recipient of
PAYCHECKS (PCK)
fk * epe_id
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 14
Relationship Mapping
Mapping of Barred Relationships
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 15
Relationship Mapping
Mapping of Barred Relationships
ACCOUNT located in BANK
# number # number
* balance * name
* date opened the location of
ACCOUNTS (ACT)
Key Type Optionality Column Name
pk * act_nbr
* balance
* date_opened
pk,fk * bak_nbr
refers
BANKS (BAK) to
Key Type Optionality Column Name
pk * bank_number
* name
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 16
Relationship Mapping
Cascade Barred Relationships
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 17
Relationship Mapping
Cascade Barred Relationships
DDS9L3 Copyright © 2015, 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 o tenant the location the location * address
of of of
DDS9L3 Copyright © 2015, 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 © 2015, Oracle and/or its affiliates. All rights reserved. 20
Relationship Mapping
Mapping Many-to-Many Relationships
DDS9L3 Copyright © 2015, 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 © 2015, Oracle and/or its affiliates. All rights reserved. 22
Relationship Mapping
Mapping One-to-One Relationships
DDS9L3 Copyright © 2015, 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 © 2015, Oracle and/or its affiliates. All rights reserved. 24
Relationship Mapping
Optional One-to-One
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 25
Relationship Mapping
Optional One-to-One
DDS9L3 Copyright © 2015, 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 the location for * description
Car-Rental Business
* model * description
fk, uk o spe_id
Parking-Lot Business
fk, uk o car_lic_plate
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 27
Relationship Mapping
Enforcing One-to-Many
DDS9L3 Copyright © 2015, 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 © 2015, 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 © 2015, Oracle and/or its affiliates. All rights reserved. 30
Relationship Mapping
Mapping Arcs
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 31
Relationship Mapping
Terminology
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 32
Relationship Mapping
Summary
DDS9L3 Copyright © 2015, Oracle and/or its affiliates. All rights reserved. 33
Relationship Mapping