You are on page 1of 18

Database Foundations

3-2
Tracking Data Changes

Copyright © 2020, Oracle and/or its affiliates. All rights reserved.


Objectives
• This lesson covers the following objective:
−Keep track of data that changes over time

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 3
Tracking Data Changes
Model Data over Time: Accommodating Historical
Data
• Most businesses need to track some historical data to help
them find trends and patterns that can be the basis for
business innovations or process improvements
• Every update of an attribute or transfer of a relationship
means loss of information. Often information is no longer
useful, but some systems must keep track of some or all of
the historical values of an attribute. In addition, some
systems are required to keep an audit trail of each
transaction
• Validate any requirements for storing historical data with
the user, because storing unnecessary historical data can
be costly

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 4
Tracking Data Changes
Model Data over Time: Accommodating Historical
Data
• Add entities and relationships to the model to
accommodate historical data
−Is an audit trail required?
−Can attribute values change over time?
−Can relationships change over time?
−Do you need to query older data?

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 5
Tracking Data Changes
Model Data over Time: Tracking Attribute Values
• Create additional entities to track the attributes' values
over time

CONTRACT
# ID
* Description Use one entity if you track only the
* Status current status of a contract
* Effective Date

Add an entity to store


contain STATUS
CONTRACT
# Effective Date
the status of a
# ID
* Description state of * Current Value contract over time

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 6
Tracking Data Changes
Model Data over Time: Accommodating a Changing
Relationship
• Add an entity to accommodate a relationship that may
change over time

PERSON APARTMENT
# ID
rent
# Code This does not allow
* Last Name rented by * Address tracking of the date that
* First Name an apartment is rented.

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 7
Tracking Data Changes
Model Data over Time: Accommodating a Changing
Relationship
• Add an entity to accommodate a relationship that may
change over time

PERSON RENTAL Add an entity to


rent
# ID # Effective Date capture the rental
* Last Name
rented by o Renewal Date relationship over
* First Name
rented for time

rented by
APARTMENT
# Code
* Address

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 8
Tracking Data Changes
Model Data over Time: Creating Intersection Entities
• Resolving M:M relationships with an intersection entity
is frequently used to track information about a
relationship that changes over time

EMPLOYEE hold JOB


# ID # ID This does not store
* Last Name held by * Title the history of an
* First Name * Minimum Salary
* Email * Maximum Salary employee’s jobs
* Hire Date
* Salary

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 9
Tracking Data Changes
Model Data over Time: Creating Intersection Entities
• An intersection entity is frequently used to track
information about a relationship that changes over
time
EMPLOYEE JOB
# ID # ID
* Last Name * Title
* First Name * Minimum Salary
* Email * Maximum Salary
* Hire Date
* Salary held by
Resolve the M:M
hold
relationship and store the JOB HISTORY
historical information in * Start Date
o End Date
the intersection entity. held for held for

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 10
Tracking Data Changes
Model Data over Time: Logging Modified Information
• Additional entities and attributes store modified
information
makes PAYMENT
CUSTOMER
# ID # Date Paid
* Name # Amount
made by
* Address
contains

included for
This stores PAYMENT MODIFICATION
information about * Previous Amount
how a payment * Modified by
* Modification Date
changes over time.

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 11
Tracking Data Changes
Model Rental over Time: Scenario
• A jewelry store rents necklaces, bracelets, and the like
for special occasions, such as award ceremonies and
movie premieres
• The store wants to track the rental history

CUSTOMER JEWELERY DETAIL


rented # code
# id
* first name renting * description
* last name * rental rate
* insured value

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 12
Tracking Data Changes
Model Rental over Time: Scenario
• The ERD model tracks only the current renter
• How would you revise the relationship to track the
history?

CUSTOMER JEWELERY DETAIL


rented # code
# id
* first name renting * description
* last name * rental rate
* insured value

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 13
Tracking Data Changes
Model Rental over Time: Scenario
• Change the relationship between JEWELRY DETAIL and
CUSTOMER to M:M.

CUSTOMER JEWELERY DETAIL


# id # code
rented
* first name * description
* last name renting * rental rate
* insured value

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 14
Tracking Data Changes
Resolve M:M
• Resolve M:M with the
RENTAL HISTORY RENTAL CUSTOMER
for
intersection entity HISTORY # id
# date on * first name
• What is the UID of * date returned * last name
RENTAL HISTORY?
for
• What piece of
on
information is not
being tracked? JEWELERY DETAIL
# code
* description
* rental rate
* insured value

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 15
Tracking Data Changes
Project Exercise
• DFo_3_2_Project
−Oracle Baseball League Store Database
−Keeping Track of Data that Changes over Time

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 16
Tracking Data Changes
Summary
• In this lesson, you should have learned how to:
−Keep track of data that changes over time

DFo 3-2 Copyright © 2020, Oracle and/or its affiliates. All rights reserved. 17
Tracking Data Changes

You might also like