DD 8 1

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

Database Design

8-1
Modeling Historical Data

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


Objectives

This lesson covers the following objectives:


• Identify the need to track data that changes over time
• Construct ERD models that incorporate elements of “data
over time”
• Identify the UID of an entity that stores historical data;
explain and justify the choice of UID

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 3
Modeling Historical Data
Purpose

• How tall were you at age 5? How tall were you at age 10?
How tall are you right now?
• If your parents wrote this down when you were young, they
were keeping track of historical data.
• Most businesses need to track some historical data.
• This helps them find trends and patterns that are the basis for
business innovations or process improvements.
• For example, rental history of a movie is useful to a video
store. It tells managers which movies are popular and which
should be moved to the back shelf.

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 4
Modeling Historical Data
Model Data Over Time

• When is it necessary to model data over time?


• Ask your client:
– Is an audit trail required?
– Can attribute values change over time?
– Can relationships change over time?
– Do you need to produce reports on older data?
– Do you need to keep previous versions of the data? If so, for
how long?

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 5
Modeling Historical Data
Data Over Time Example

• An organization needs to keep data about


EMPLOYEE
employees’ salaries. # id
* first name
• All employees are paid weekly. * last name
* weekly salary amount
• Initially, the following EMPLOYEE entity * salary start date
was modeled.
• Additional requirements now specify that
the organization needs to keep a
historical record of how and when
employees’ salaries have changed during
their employment.

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 6
Modeling Historical Data
Model Salary Changes

• To model salary changes over time, add a SALARY HISTORY


entity.
SALARY HISTORY EMPLOYEE
# salary start date for # id
o salary end date * first name
* weekly salary having * last name
amount

• The UID of the SALARY HISTORY entity is the related


EMPLOYEE id and the salary start date.

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 7
Modeling Historical Data
Model Rental Over Time

• A jewelry store rents pieces (necklaces, bracelets and so on)


to movie stars for special occasions, such as award
ceremonies or movie premieres.
• They would like to track the rental history of a jewelry piece.
• The following ER model will only track the current renter of a
piece of jewelry.
• How would you revise the relationship to track history?
JEWELRY PIECE MOVIE STAR
# code rented by # id
* description * first name
renting * last name
* rental rate
* insured value

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 8
Modeling Historical Data
Resolve M:M
JEWELRY PIECE MOVIE STAR
rented by # id
# code
* description * first name
• The relationship between * rental rate renting * last name
JEWELRY PIECE and MOVIE * insured value
STAR should be revised to a The M:M relationship is resolved with an
M:M, which is then resolved intersection entity.
with an intersection entity
RENTAL HISTORY for MOVIE STAR
RENTAL HISTORY. * rental date # id
* first name
• Next we need to determine * date returned on
* last name
the UID of RENTAL HISTORY. for
on
JEWELRY PIECE
# code
* description
* rental rate
* insured value

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 9
Modeling Historical Data
Determine UID

• Option 1: Barred
relationship. RENTAL HISTORY for
* rental date
MOVIE STAR
# id

• Drawing a Barred on
* date returned * first name
* last name
relationship is not a for
suitable UID here, as
this would not allow a on
MOVIE STAR to rent JEWELRY PIECE
the same JEWELRY # code
* description
PIECE on different * rental rate
dates * insured value

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 10
Modeling Historical Data
Determine UID

• Option 2: Barred
relationship and Rental RENTAL HISTORY for
# rental date
MOVIE STAR
# id
Date. * date returned on * first name
* last name
• Adding rental date to the for
UID would allow a MOVIE
STAR to rent the same on
JEWELRY PIECE on JEWELRY PIECE
different dates, but # code
* description
would also permit * rental rate
different MOVIE STARS * insured value

to rent the same JEWELRY


PIECE on the same date!

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 11
Modeling Historical Data
Determine UID

• Option 3: Barred
relationship between RENTAL HISTORY for
# rental date
MOVIE STAR
# id
MOVIE STAR and * date returned on * first name
RENTAL HISTORY with * last name

Rental Date. for

• This model would not on


permit the same JEWELRY PIECE
MOVIE STAR to rent # code
* description
more than one * rental rate
JEWELRY PIECE on a * insured value

given day.

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 12
Modeling Historical Data
Determine UID

• Option 4: Barred
relationship between RENTAL HISTORY for
# rental date
MOVIE STAR
# id
JEWELRY PIECE and * date returned on * first name
RENTAL HISTORY with * last name

Rental Date. for

• This model says that a on


JEWELRY PIECE can be JEWELRY PIECE
rented only once on the # code
* description
same date. * rental rate
* insured value

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 13
Modeling Historical Data
Terminology

Key terms used in this lesson included:


• Audit trail
• Historical data

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 14
Modeling Historical Data
Summary

In this lesson, you should have learned how to:


• Identify the need to track data that changes over time
• Construct ERD models that incorporate elements of “data
over time”
• Identify the UID of an entity that stores historical data;
explain and justify the choice of UID

DDS8L1 Copyright © 2017, Oracle and/or its affiliates. All rights reserved. 15
Modeling Historical Data

You might also like