database technology topic 3: enhanced entity- relationship ...tddd37/fo/dbtechnology03-2017.pdf ·...

Post on 03-Jul-2018

236 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Database Technology

Topic 3: Enhanced Entity-Relationship (EER) ModelingOlaf Hartigolaf.hartig@liu.se

2Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Example

A taxi company needs to model their activities.

There are two types of employees in the company: drivers and operators. For drivers it is interesting to know the date of issue and type of the driving license, and the date of issue of the taxi driver’s certificate. For all employees it is interesting to know their personal number, address and the available phone numbers.

The company owns a number of cars. For each car there is a need to know its type, year of manufacturing, number of places in the car and date of the last service.

The company wants to have a record of car trips. A taxi may be picked on a street or ordered through an operator who assigns the order to a certain driver and a car. Departure and destination addresses together with times should also be recorded.

3Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Recall: DB Design Process

4Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Entity-Relationship (ER) Model

High-level conceptual data model An overview of the database Easy to discuss with non-database experts Easy to translate to data model of DBMS

ER diagram Diagrammatic notation associated with the ER model

5Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Entities and Entity Types

Entity: a ”thing” in the real world with an independent existence

Attributes: Properties that describe an entity Entity type: A collection of entities that have

the same set of attributes

Car

RegNumber

Model

Year

Owner

SSN Name

6Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Attributes

simple versus composite single-valued versus multivalued stored versus derived

Owner

SSN

Name

Age

Address

CityStreet

PhoneNumber

7Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Constraints on Attributes

Value sets (domains) of attributes Key attributes

Owner

SSN

Name

Age

Address

CityStreet

PhoneNumber

8Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Relationship Types

Relationship type: Association among entity types

owns Car

RegNumber

Model

Year

NOwner

SSN Name

1

9Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Constraints on Relationship Types

Cardinality ratio: Maximum number of relationships an entity can participate in

Possible cardinality ratio: 1:1, 1:N, N:1, and N:M

Owner Carowns1 N

Owner CarownsN 1

Owner CarownsN M

10Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Constraints on Relationship Types

Participation constraint Total participation: Every entity participates

in at least one relationship with another entity

Owner CarownsN M

”Every car must be owned by at least one owner.”

SSN RegNumber

11Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Attributes of Relationship Types

Car

SSN

Name RegNumber

Model

Year

N M

”Store information on who owned which car and during which period of time”

SellDate

BuyDate

ownsOwner

12Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

n-ary Relationships

Example: A person works as an engineer at one company and as a gym instructor at another company

Company

Employee

JobType

works at

works as

N

N

M

M

Employee JobType

Company

works as

N M

K Ternary

13Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Weak Entity Types

Identified by their relationship to a specific entity from another entity type

Do not have key attributes of their own Only partial key The identifying entity has the rest of the key

PlayerN number

Team1

plays_in

name

name

14Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

ER Notation

EnhancedEntity-Relationship (EER) Model

16Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Enhanced ER (EER) Model

Why more? To support more complex data requirements Example: Only some employees can use a company

car, only managers have to write a monthly report, but all employees have assigned personal number, salary account and a place in the office.

What more? Specialization / generalization Subtype / supertype Union subtypes Attribute and relationship inheritance

17Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Subtype / Supertype

PNName

Surname FirstName

Salesman Engineer Manager ProjectLeader

o

U U

U

Car

uses

1

MonthlyReport

writes

1

1 N

RegNumber ReportID

Employee

dCommission

spec

ializ

atio

n

gene

raliz

atio

n

process ofdefiningtypes

18Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Constraints on Subtypes

Disjointness constraint

• Specifies that the subclasses of the specialization must be disjoint

• Otherwise ”overlapping”

Completeness constraint (or totalness constraint)

• Specifies that every superclass entity must be in a subclass• Otherwise ”partial”

Disjointness and completeness are independent constraints

• i.e., four cases are possible• disjoint and total• disjoint and partial• overlapping and total• overlapping and partial

Example

22Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Example

A taxi company needs to model their activities.

There are two types of employees in the company: drivers and operators. For drivers it is interesting to know the date of issue and type of the driving license, and the date of issue of the taxi driver’s certificate. For all employees it is interesting to know their personal number, address and the available phone numbers.

The company owns a number of cars. For each car there is a need to know its type, year of manufacturing, number of places in the car and date of the last service.

The company wants to have a record of car trips. A taxi may be picked on a street or ordered through an operator who assigns the order to a certain driver and a car. Departure and destination addresses together with times should also be recorded.

23Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Example

DrivingLicenseType

DrivingLicenseDate

Employee

Driver Operator

Car

assign

PNAddressStreet

TownPostNumber

Phone

oUU

RegNumber

Type

YearOfManuf

ServiceDate

PlacesID

DestTime

DepTime

Destination

DeparturePlace

TaxiCertifDate

DrivingLicenseDate

DrivingLicenseType 1

N

1

N

N

1made_by

Trip

drives

24Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Example (cont'd)

A driver may have many driving licenses (types)

Driver

TaxiCertifDate

Körkort

Date Type

Id

1N

Driver

TaxiCertifDate

DrivingLicense

Date

Type

belongsToN M

Driver

TaxiCertifDate

DrivingLicenseDate

DrivingLicenseType

DrivingLicense belongsTobelongsTo

Summary

26Database TechnologyTopic 3: Enhanced Entity-Relationship (EER) Modeling

Summary

Entity-relationship (ER) model: a graphical way to model the world

Main concepts:– Entity type– Relationship type– Attributes

Different types of constraints Enhanced ER model

top related