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

Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

  • Upload
    others

  • View
    4

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

Database Technology

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

Page 2: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

2Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

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

Recall: DB Design Process

Page 4: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

4Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

5Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

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

Attributes

simple versus composite single-valued versus multivalued stored versus derived

Owner

SSN

Name

Age

Address

CityStreet

PhoneNumber

BDate

Page 7: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

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

Constraints on Attributes

Value sets (domains) of attributes Key attributes

Owner

SSN

Name

Age

Address

CityStreet

PhoneNumber

BDate

Page 8: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

8Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

9Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

10Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

11Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

12Database TechnologyTopic 4: 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 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

13Database TechnologyTopic 4: 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

RoomN number

Hotel1

has_room

name

type

Page 14: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

EnhancedEntity-Relationship (EER) Model

Page 15: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

15Database TechnologyTopic 4: 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 16: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

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

Subtype / Supertype

PNName

Surname FirstName

Salesman Engineer Manager ProjectLeader

o

U 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 17: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

17Database TechnologyTopic 4: 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 18: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

www.liu.se

Page 19: Database Technology Topic 4: Enhanced Entity- Relationship …TDDD37/fo/DBTechnology04-2020.pdf · 2020. 1. 31. · Topic 4: Enhanced Entity-Relationship (EER) Modeling Example A

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

Total Participation Constraint

Total participation: Every entity participatesin at least one relationship with another entity

Alternative notations:– either double line (as in my earlier lecture slides)– or lower-bound cardinality (as in the video lecture)

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

Owner CarownsN M

SSN RegNumber

Owner Carowns1..N 0..M

SSN RegNumber