46
Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling 1

Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Embed Size (px)

Citation preview

Page 1: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Database Design

Sections 9 & 10Modeling Historical Data, conditional nontranferability, time-related constraints,Database conventions, generic modeling

1

Page 2: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Modeling Over Time

Any relationship that changes through time needs special consideration.

An attribute such as status may change over time.

Examples of time sensitive attributes are: rental status, fee payment, country name, or price

2

Page 3: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Change and Time

1. Every attribute update means loss of information.

2. Time in your model makes the model more complex.

3. There are often complex join conditions.

4. Users can work in advance.

3

Page 4: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Why Modeling Time examples

Track trends in products City police department tracks crimes

in each neighborhood frequency of crimes during certain times

of the year holidays or during really hot or cold

weather

4

Page 5: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Entity DAY or Attribute Date Single attribute

entity without M:1 relationships is usually replaced by attribute

PURCHASE* date

PURCHASE

DAY #date

on

for

5

Page 6: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

What is wrong with revision?

6

Page 7: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Entity Day vs. Attribute Date

7

Page 8: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Examples

When there is an interest in a particular day not a date. Is it a holiday? Is it a work day or weekend? Is it leap year? Month end?

8

Page 9: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Entity DAY

TASK ASSIGNMENT*duration in hours

TASK#id

DAY #date

* public holiday indicator

EMPLOYEE#name

first day of

starts on

for

of

in

with

9

Page 10: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Time-related Contstraints

10

Page 11: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Modeling time constraint example 1

Be aware of constraints that can result from the time dimension. Here is an example:

Consider a school fair that features several booths. The manager signs up volunteers to work different shifts at different booths. Some volunteers can work for several hours; others can work fewer hours depending on their free time. The schedule has to be determined in advance, so that the manager knows which times are not covered by any volunteers.

11

Page 12: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Example 2

12

Page 13: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Review example 1-

What are some other rules?13

Page 14: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Modeling Change

ASSIGNMENT#start dateo end date

EMPLOYEE#id

COUNTRY#name

of

for

in

as

14

Page 15: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Modeling Change

ASSIGNMENT#start dateo end date

EMPLOYEE#id

COUNTRY#name

#start time*end time

of

for

in

as

life cycle attributes

Even a Country has a life cycle

15

Page 16: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Modeling change: Price

When do we need to track price? Determine best price for item Sale price vs. original price Grade change Value of home Asking price vs. sale price Stock, bond, or investment Others

16

Page 17: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Mapping Historical Price

PRICE = PRICED PRODUCT = HISTORICAL PRICE

PRODUCT#id

*name

PRICE#start date

*price $o end date

have

for

17

Page 18: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Slide 11

18

Page 19: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Revised previous ERD

19

Page 20: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Price Changes

Stock Market – example Price changes with time (seconds) Need to know to buy/sell Trends in price effects decisions

20

Page 21: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Price with time

Price may fluctuate with time “The Good Old Days” Examples:

Value of Gold or Silver Real Estate Value of currency Gasoline

21

Page 22: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Journaling

22

Page 23: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

23

Page 24: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Example

When a student’s grade is changed, we need to record information on the teacher who changed the grade and the reason for the change.

Start with the ENROLLMENT entity, which is the resolution of the M:M between STUDENT and CLASS.

24

Page 25: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Solution 10.2.13

STUDENT

CLASS

ENROLLMENT#date*grade

GRADE CHANGE*old grade

*changed by#date changed

o reason for change

Student / ClassM:M

Enrollment is the intersection entity

25

Page 26: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Adding the Time element to ERD

When does a school need to keep time related information?

Could these be similar to issues in a business

26

Page 27: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Drawing Conventions

Improve readability Examples from “DJs on Demand”

scenario Dividing a big ERD up into functional

areas

27

Page 28: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Marge Hohly 28

Conventions Review Crows feet

Crows fly East and South Divide complex ERD’s into functional areas Place Highest volume entities in upper left

corner Improve readability

avoid criss-crossing lines increase white spaces so relationships don’t

overlap be consistent with font type, size, and styles

28

Page 29: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

29

Page 30: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

30

Page 31: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

31

Page 32: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

32

Page 33: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

33

Page 34: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

34

Page 35: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

35

Page 36: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Marge Hohly 36

Generic Modeling Can reduce number of entities in diagram Can provide more flexibility in unstable

situations (where business requirements change often)

Use a more distant perspective See next slide. What would happen to the

generic model if we had to add 10 new ARTICLE types, each with their own attributes?

36

Page 37: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

37

Page 38: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Marge Hohly 38

Generic Modeling Have more attributes in fewer entities Many mandatory requirements/attributes

become optional Structural rules become procedural rules Example: PANTS waist size was mandatory,

with ARTICLE waist size becomes optional What other businesses would be good

candidates for generic modeling?

38

Page 39: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

39

Page 40: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

40

Page 41: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

41

Page 42: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

42

Page 43: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

43

Page 44: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Generic Model - Benefits

Benefits Flexibility – can prevent need to change

data structure Can reduce the number of entities

dramatically

Disadvantages Increased complexity is both data model

and application programs

44

Page 45: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Marge Hohly 45

Relational Database Concepts

Conceptual model transforms into a relational database

A relational database is a database that is perceived by the user as a collection of relations or two-dimensional tables.

Table, each employee (instances), and each column (attribute)

45

Page 46: Database Design Sections 9 & 10 Modeling Historical Data, conditional nontranferability, time-related constraints, Database conventions, generic modeling

Conventions Review

Crows feet Crows fly East and South Divide complex ERD’s into functional areas Place highest volume entities in upper left

corner Improve readability

Avoid criss-crossing lines Increase white spaces so relationships don’t

overlab Be consistent with font type, size, and styles

46