Database System Concepts - Chapter 6: Entity-Relationship Model

37
Database System Concepts Modeling Concepts Entity- Relationship Diagrams Extended E-R Features E-R Design Database System Concepts Chapter 6: Entity-Relationship Model Departamento de Engenharia Inform´ atica Instituto Superior T´ ecnico 1 st Semester 2008/2009 Slides (fortemente) baseados nos slides oficiais do livro “Database System Concepts” c Silberschatz, Korth and Sudarshan.

Transcript of Database System Concepts - Chapter 6: Entity-Relationship Model

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Database System ConceptsChapter 6: Entity-Relationship Model

Departamento de Engenharia InformaticaInstituto Superior Tecnico

1st Semester2008/2009

Slides (fortemente) baseados nos slides oficiais do livro“Database System Concepts”c©Silberschatz, Korth and Sudarshan.

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Outline

1 Modeling Concepts

2 Entity-Relationship Diagrams

3 Extended E-R Features

4 E-R Design

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Outline

1 Modeling Concepts

2 Entity-Relationship Diagrams

3 Extended E-R Features

4 E-R Design

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Modeling

A database can be modeled as:

a collection of entities,relationship among entities.

An entity is an object that exists and is distinguishablefrom other objects.

Example: specific person, company, event, plant

Entities have attributes

Example: people have names and addresses

An entity set is a set of entities of the same type thatshare the same properties.

Example: set of all persons, companies, trees, holidays

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Entity Sets customer and loan

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Relationship Sets

A relationship is an association among several entities

Example: depositor is a relationship between customer

and account

A relationship set is a mathematical relation among n ≥ 2entities, each taken from entity sets

{(e1, e2, . . . , en)|e1 ∈ E1, e2 ∈ E2, . . . , en ∈ En}

where (e1, e2, . . . , en) is a relationship

Example:(Hayes, A − 102) ∈ depositor

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Relationship Set borrower

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Relationship Set Attributes

An attribute can also be property of a relationship set.For instance, the depositor relationship set between entitysets customer and account may have the attributeaccess-date

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Degree of a Relationship Set

Refers to number of entity sets that participate in arelationship set.

Relationship sets that involve two entity sets are binary (ordegree two).

Relationship sets may involve more than two entity sets.

Example: Suppose employees of a bank may have jobs(responsibilities) at multiple branches, with different jobsat different branches. Then there is a ternary relationshipset between entity sets employee, job, and branch

Relationships between more than two entity sets are rare.Most relationships are binary.

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Attributes

An entity is represented by a set of attributes, that isdescriptive properties possessed by all members of anentity set.

Example:

customer = (customer_id, customer_name,

customer_street, customer_city)

loan = (loan_number, amount)

Domain - the set of permitted values for each attribute

Attribute types:

Simple and composite attributes.Single-valued and multi-valued attributes

Example: multivalued attribute: phone numbers

Derived attributes

Can be computed from other attributes

Example: age, given date of birth

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Mapping Cardinality Constraints

Express the number of entities to which another entity canbe associated via a relationship set.

Most useful in describing binary relationship sets.

For a binary relationship set the mapping cardinality mustbe one of the following types:

One to oneOne to manyMany to oneMany to many

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Mapping Cardinalities

One to one One to many

Note: Some elements in A and B may not be mapped to anyelements in the other set

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Mapping Cardinalities

Many to one Many to many

Note: Some elements in A and B may not be mapped to anyelements in the other set

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Keys

A super key of an entity set is a set of one or moreattributes whose values uniquely determine each entity.

A candidate key of an entity set is a minimal super key

Customer id is candidate key of customeraccount number is candidate key of account

Although several candidate keys may exist, one of thecandidate keys is selected to be the primary key.

The combination of primary keys of the participatingentity sets forms a super key of a relationship set.

(customer id, account number) is the super key ofdepositorMust consider the mapping cardinality of the relationshipset when deciding the what are the candidate keys

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Outline

1 Modeling Concepts

2 Entity-Relationship Diagrams

3 Extended E-R Features

4 E-R Design

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

E-R Diagrams

Rectangles represent entity sets.

Diamonds represent relationship sets.

Lines link attributes to entity sets and entity sets torelationship sets.

Ellipses represent attributes

Double ellipses represent multivalued attributes.Dashed ellipses denote derived attributes.

Underline indicates primary key attributes

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

E-R Diagram With Composite, Multivalued, andDerived Attributes

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Relationship Sets with Attributes

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Roles

Entity sets of a relationship need not be distinct

The labels “manager” and “worker” are called roles; theyspecify how employee entities interact via the works for

relationship set.

Roles are indicated in E-R diagrams by labeling the lines thatconnect diamonds to rectangles.

Role labels are optional, and are used to clarify semantics of therelationship

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Cardinality Constraints

We express cardinality constraints by drawing either adirected line (→), signifying “one”, or an undirected line(−), signifying “many”, between the relationship set andthe entity set.

many-to-many relationship

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Cardinality Constraints

We express cardinality constraints by drawing either adirected line (→), signifying “one”, or an undirected line(−), signifying “many”, between the relationship set andthe entity set.

one-to-many relationship

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Cardinality Constraints

We express cardinality constraints by drawing either adirected line (→), signifying “one”, or an undirected line(−), signifying “many”, between the relationship set andthe entity set.

many-to-one relationship

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Participation of an Entity Set in a Relationship Set

Total participation (double line): every entity in the entityset participates in at least one relationship in therelationship set

E.g. participation of loan in borrower is total: every loanmust have a customer associated to it via borrower

Partial participation: some entities may not participate inany relationship in the relationship set

Example: participation of customer in borrower is partial

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

E-R Diagram with a Ternary Relationship

Cardinality Constraints:

We allow at most one arrow out of a ternary (or greaterdegree) relationship to indicate a cardinality constraintE.g. an arrow from works on to job indicates eachemployee works on at most one job at any branch.

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Weak Entity Set

An entity set that does not have a primary key is referredto as a weak entity set.

The existence of a weak entity set depends on theexistence of a identifying entity set

it must relate to the identifying entity set via a total,

one-to-many relationship set from the identifying to theweak entity setIdentifying relationship depicted using a double diamond

The discriminator (or partial key) of a weak entity set isthe set of attributes that distinguishes among all theentities of a weak entity set.

The primary key of a weak entity set is formed by theprimary key of the strong entity set on which the weakentity set is existence dependent, plus the weak entityset’s discriminator.

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Weak Entity Set (cont.)

We depict a weak entity set by double rectangles.

We underline the discriminator of a weak entity set with adashed line.

payment number - discriminator of the payment entity set

Primary key for payment - (loan number,

payment number)

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Outline

1 Modeling Concepts

2 Entity-Relationship Diagrams

3 Extended E-R Features

4 E-R Design

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Specialization/Generalization

Depicted by a triangle component labeled ISA (E.g. customer“is a” person).

Attribute inheritance - a lower-level entity set inherits all theattributes and relationship participation of the higher-levelentity set to which it is linked.

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Constraints on a Specialization/Generalization

Constraint on whether or not entities may belong to morethan one lower-level entity set within a singlegeneralization.

Disjoint - an entity can belong to only one lower-levelentity set

Noted in E-R diagram by writing disjoint next to the ISA

triangle

Overlapping - an entity can belong to more than onelower-level entity set

Completeness constraint specifies whether or not an entityin the higher-level entity set must belong to at least one ofthe lower-level entity sets within a generalization.

Total - an entity must belong to one of the lower-levelentity sets

Noted in E-R diagram by a double line over the ISA

triangle

Partial - an entity need not belong to one of the lower-levelentity sets

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Aggregation

Consider the ternary relationship works on, which we saw earlierSuppose we want to record managers for tasks performed by anemployee at a branch

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Outline

1 Modeling Concepts

2 Entity-Relationship Diagrams

3 Extended E-R Features

4 E-R Design

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Design Issues

The use of an attribute or entity set to represent an object.

Whether a real-world concept is best expressed by anentity set or a relationship set.

The use of a ternary relationship versus a pair of binaryrelationships.

The use of a strong or weak entity set.

The use of specialization/generalization - contributes tomodularity in the design.

The use of aggregation - can treat the aggregate entity setas a single unit without concern for the details of itsinternal structure.

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Mapping Cardinalities affect ER Design

Can make access-date an attribute of account, instead ofa relationship attribute, if each account can have only onecustomer

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

Mapping Cardinalities affect ER Design

Can make access-date an attribute of account, instead ofa relationship attribute, if each account can have only onecustomer

E-R Diagram for a Banking Enterprise

Summary of Symbols Used in E-R Notation

DatabaseSystem

Concepts

ModelingConcepts

Entity-RelationshipDiagrams

Extended E-RFeatures

E-R Design

End of Chapter 6