Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf ·...

24
Database Technology Topic 3: Enhanced Enty- Relaonship (EER) Modeling Olaf Harg [email protected]

Transcript of Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf ·...

Page 1: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

Database Technology

Topic 3: Enhanced Entity-Relationship (EER) ModelingOlaf [email protected]

Page 2: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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.

Page 3: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Recall: DB Design Process

Page 4: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 5: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 6: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 7: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 8: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 9: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 10: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 11: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 12: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 13: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 14: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

ER Notation

Page 15: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

EnhancedEntity-Relationship (EER) Model

Page 16: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 17: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 18: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 19: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

Example

Page 20: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling 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.

Page 21: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 22: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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

Page 23: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

Summary

Page 24: Database Technology Topic 3: Enhanced Entity- Relationship ...TDDD37/fo/DBTechnology03-2017.pdf · 2 Database Technology Topic 3: Enhanced Entity-Relationship (EER) Modeling Example

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