Databases – Data...
Transcript of Databases – Data...
![Page 1: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/1.jpg)
Databases – Data Modelling
Jörg Endrullis
VU University Amsterdam
![Page 2: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/2.jpg)
Data Modelling :: Phases of Database Design
![Page 3: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/3.jpg)
Database Design
Database Design
formal model of the relevant aspects of the real word
the real world serves as measure of correctness
The database states should correspond to the states of the real world.
Database design is challenging:
Expertise:requires expertise in the application domain
Flexibility:real world often permits exceptional cases
Size:database schema may become huge
![Page 4: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/4.jpg)
Database Design
Database Design
formal model of the relevant aspects of the real word
the real world serves as measure of correctness
The database states should correspond to the states of the real world.
Database design is challenging:
Expertise:requires expertise in the application domain
Flexibility:real world often permits exceptional cases
Size:database schema may become huge
![Page 5: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/5.jpg)
Database Design
Due to the complexity, the design is a multi-step process. . .
Three Phases of Database DesignConceptual Database Design
what information do we storehow are the information elements related to each otherwhat are the constraints?e.g. ER model or UML model
Logical Database Designtransformation of the conceptual schema into the schemasupported by the databasee.g. relational model
Physical Database Designdesign indexes, table distribution, buffer sizes,. . .to maximise performance of the final system
![Page 6: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/6.jpg)
Data Modelling :: Entity-Relationship Model
![Page 7: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/7.jpg)
Entity-Relationship Model
customer
idname
street
city
account
account-number
balance
depositor
The three main ingredients of entity-relationship diagrams are:
Entity sets
Attributes
Relationship sets
![Page 8: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/8.jpg)
Entity-Relationship Model
customer
idname
street
city
account
account-number
balance
depositor
Rectangles represent entity sets
Ellipses represent attributes
Double ellipses represent multi-valued attributes
Dashed ellipses denote derived attributes
Diamonds represent relationship setsLines link attributes and relationship sets to entity setsUnderline indicates primary key attributes
![Page 9: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/9.jpg)
Entity Sets
An entity is an abstract objecte.g.: specific person, company, event
Entities have attributese.g.: people have names and addresses
An entity set is a collection of similar entitiessimilar = sharing the same properties (attributes)e.g.: set of all persons, companies, trees, holidays
Comparison with object-oriented programming:
entity ≈ object entity set ≈ class
Important difference: the ER model is staticmodels structure of the data, not the operationsno methods/functions associated to entity sets
![Page 10: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/10.jpg)
Entity Sets
An entity is an abstract objecte.g.: specific person, company, event
Entities have attributese.g.: people have names and addresses
An entity set is a collection of similar entitiessimilar = sharing the same properties (attributes)e.g.: set of all persons, companies, trees, holidays
Comparison with object-oriented programming:
entity ≈ object entity set ≈ class
Important difference: the ER model is staticmodels structure of the data, not the operationsno methods/functions associated to entity sets
![Page 11: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/11.jpg)
Entity Sets
An entity is an abstract objecte.g.: specific person, company, event
Entities have attributese.g.: people have names and addresses
An entity set is a collection of similar entitiessimilar = sharing the same properties (attributes)e.g.: set of all persons, companies, trees, holidays
Comparison with object-oriented programming:
entity ≈ object entity set ≈ class
Important difference: the ER model is staticmodels structure of the data, not the operationsno methods/functions associated to entity sets
![Page 12: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/12.jpg)
Attributes
An entity set is represented by a set of attributes, that is,properties possessed by all entities of the entity set.
Customer = (id, name, street, city)Loan = (loan-number, amount)
Attribute typessimple and composite attributes
e.g. street is composed of street name and numbersingle-valued and multi-valued attributes
e.g. single-valued: age of a persone.g. multi-valued: person can have multiple phone numbers
derived attributescan be computed from other attributese.g. age can be computed given the date of birth
![Page 13: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/13.jpg)
Attributes
An entity set is represented by a set of attributes, that is,properties possessed by all entities of the entity set.
Customer = (id, name, street, city)Loan = (loan-number, amount)
Attribute typessimple and composite attributes
e.g. street is composed of street name and numbersingle-valued and multi-valued attributes
e.g. single-valued: age of a persone.g. multi-valued: person can have multiple phone numbers
derived attributescan be computed from other attributese.g. age can be computed given the date of birth
![Page 14: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/14.jpg)
Attributes
customerid
name
first-name
middle-initial
last-name
address
zip-code
state
city
street
street-number
street-name
phone-numbers
date-of-birthage
name, address and street are composite attributesphone numbers is a multi-valued attributeage is a derived attribute (derived from date-of-birth)
![Page 15: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/15.jpg)
Relationship Sets
Uma ThurmanMark Hamill
Harrison Ford
Pulp FictionStar Wars
Indiana Jonesactor
entity setmovie
entity setplays-in
relationship set
A relationship is an association among several entities.
Formally, a relationship is a tuple (e1,e2, . . . ,en) of entities.
(Mark Hamill, Star Wars) is a relationship(Harrison Ford, Indiana Jones) is a relationship
![Page 16: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/16.jpg)
Relationship Sets
Uma ThurmanMark Hamill
Harrison Ford
Pulp FictionStar Wars
Indiana Jonesactor
entity setmovie
entity setplays-in
relationship set
A relationship is an association among several entities.
Formally, a relationship is a tuple (e1,e2, . . . ,en) of entities.
(Mark Hamill, Star Wars) is a relationship(Harrison Ford, Indiana Jones) is a relationship
![Page 17: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/17.jpg)
Relationship Sets
Uma ThurmanMark Hamill
Harrison Ford
Pulp FictionStar Wars
Indiana Jonesactor
entity setmovie
entity setplays-in
relationship set
A relationship set is a set of relationships of the same kind.
That is, a relationship set is a set of tuples (e1,e2, . . . ,en)where e1 ∈ E1, . . . , en ∈ En are from entity sets E1, . . . ,En.
Example of a relationship set
{ (Uma Thurman, Pulp Fiction),(Mark Hamill, Star Wars),(Harrison Ford, Star Wars),(Harrison Ford, Indiana Jones) }
![Page 18: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/18.jpg)
Relationship Sets
Uma ThurmanMark Hamill
Harrison Ford
Pulp FictionStar Wars
Indiana Jonesactor
entity setmovie
entity setplays-in
relationship set
A relationship set is a set of relationships of the same kind.
That is, a relationship set is a set of tuples (e1,e2, . . . ,en)where e1 ∈ E1, . . . , en ∈ En are from entity sets E1, . . . ,En.
The relationship set plays-in between entity sets actor andmovie is indicated as follows in ER models:
actor movieplays-in
![Page 19: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/19.jpg)
Relationship Sets and Role Names
The relationship set connections can be annotated with roleindicators.
buys-fromcustomerbuyer shopseller
Role indicators improve readability!
![Page 20: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/20.jpg)
Degree of a Relationship Set
The degree of a relationship set refers to the number of entitysets participating in the relationship.
relationship sets of degree 2 are called binaryrelationship sets of degree 3 are called ternary
Example for a ternary relationship set works-on: an employeemight work on different jobs at different branches of a company.
employee
employee-id
name branch
branch-name
city
job
title level
works-on
![Page 21: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/21.jpg)
Degree of a Relationship Set
A B
C
R
Non-binary relationship sets can be represented using binaryones by creating an artificial entity set.
A B
C
ERA RB
RC
![Page 22: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/22.jpg)
Data Modelling :: Cardinality Limits
![Page 23: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/23.jpg)
Cardinality Limits
Cardinality limits express the number of entities to whichanother entity can be associated via a relationship set.
There are many different notations. We use the UML notation!
RAM1..M2 B
N1..N2
Every entity a from A is connected toat least N1, and at most N2 entities in B.
Every entity b from B is connected toat least M1, and at most M2 entities in A.
Typical cardinality constraints
0..1 = zero or one 0..∗ = any number1..1 = precisely one 1..∗ = at least one
![Page 24: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/24.jpg)
Cardinality Limits: Many-to-Many
RA0..∗
B0..∗
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5
a6 b6
a7 b7
This describes a many-to-many relationship set:the entities may be connected arbitrarilyevery a in A can be linked to an arbitrary number of B’severy b in B can be linked to an arbitrary number of A’s
If the cardinalities are not given, the default is many-to-many.
![Page 25: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/25.jpg)
Cardinality Limits: One-to-One
RA1..1
B1..1
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5
a6 b6
This describes a one-to-one relationship set:every a in A is connected to precisely one b in Bevery b in B is connected to precisely one a in A
Note that this corresponds to a bijective function from A to B.
![Page 26: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/26.jpg)
Cardinality Limits: Zero or One-to-Zero or One
RA0..1
B0..1
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5
a6 b6
This describes a zero or one-to-zero or one relationship set:every a in A is connected to at most one (= 0 or 1) b in Bevery b in B is connected to at most one (= 0 or 1) a in A
Confusingly, this is sometimes also called one-to-one.
![Page 27: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/27.jpg)
Cardinality Limits: One-to-Many
RA1..1
B0..∗
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5
a6 b6
This describes a one-to-many relationship set:every a in A is related to an arbitrary number b’s in Bevery b in B is connected to precisely one a in A
![Page 28: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/28.jpg)
Cardinality Limits: Zero or One-to-Many
RA0..1
B0..∗
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5
a6 b6
This describes a zero or one-to-many relationship set:.every a in A is related to an arbitrary number b’s in Bevery b in B is connected to at most one a in A
Confusingly, this is sometimes also called one-to-many.
![Page 29: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/29.jpg)
Cardinality Limits: Many-to-One
RA0..∗
B1..1
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5
a6 b6
This describes a many-to-one relationship set:every b in B is related to an arbitrary number of a’s in Aevery a in A is connected to precisely one b in B
![Page 30: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/30.jpg)
Cardinality Limits: Many-to-Zero or One
RA0..∗
B0..1
a1 b1
a2 b2
a3 b3
a4 b4
a5 b5
a6 b6
This describes a many-to-zero or one relationship set:every b in B is related to an arbitrary number of a’s in Aevery a in A is connected to at most one b in B
Confusingly, this is sometimes also called many-to-one.
![Page 31: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/31.jpg)
Express the following Cardinality Limits
Every a in A is connected to precisely one b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..1
Every a in A is connected to one or more b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..∗
Every a in A is connected to one or more b in B,and every b in B is connected to precisely one a in A.
RA1..1
B1..∗
![Page 32: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/32.jpg)
Express the following Cardinality Limits
Every a in A is connected to precisely one b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..1
Every a in A is connected to one or more b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..∗
Every a in A is connected to one or more b in B,and every b in B is connected to precisely one a in A.
RA1..1
B1..∗
![Page 33: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/33.jpg)
Express the following Cardinality Limits
Every a in A is connected to precisely one b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..1
Every a in A is connected to one or more b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..∗
Every a in A is connected to one or more b in B,and every b in B is connected to precisely one a in A.
RA1..1
B1..∗
![Page 34: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/34.jpg)
Express the following Cardinality Limits
Every a in A is connected to precisely one b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..1
Every a in A is connected to one or more b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..∗
Every a in A is connected to one or more b in B,and every b in B is connected to precisely one a in A.
RA1..1
B1..∗
![Page 35: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/35.jpg)
Express the following Cardinality Limits
Every a in A is connected to precisely one b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..1
Every a in A is connected to one or more b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..∗
Every a in A is connected to one or more b in B,and every b in B is connected to precisely one a in A.
RA1..1
B1..∗
![Page 36: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/36.jpg)
Express the following Cardinality Limits
Every a in A is connected to precisely one b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..1
Every a in A is connected to one or more b in B,and every b in B is connected to at most one a in A.
RA0..1
B1..∗
Every a in A is connected to one or more b in B,and every b in B is connected to precisely one a in A.
RA1..1
B1..∗
![Page 37: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/37.jpg)
Cardinality Limits: Alternative Notations
There are many different notations for ER models.
For example:
RA B is alternative for RA0..∗
B0..∗
RA B is alternative for RA0..1
B0..∗
RA B is alternative for RA0..∗
B0..1
RA B is alternative for RA0..1
B0..1
![Page 38: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/38.jpg)
Cardinality Limits: Alternative Notations
There are many different notations for ER models.
For example:
RA B is alternative for RA0..∗
B0..∗
RA B is alternative for RA0..1
B0..∗
RA B is alternative for RA0..∗
B0..1
RA B is alternative for RA0..1
B0..1
![Page 39: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/39.jpg)
Cardinality Limits: Alternative Notations
There are many different notations for ER models.
For example: Information engineering style
![Page 40: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/40.jpg)
Cardinality Limits: Alternative Notations
There are many different notations for ER models.
For example: Chen style
![Page 41: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/41.jpg)
Cardinality Limits: Alternative Notations
There are many different notations for ER models.
For example: Bachman style
![Page 42: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/42.jpg)
Cardinality Limits: Alternative Notations
There are many different notations for ER models.
For example: Martin style
![Page 43: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/43.jpg)
Total Participation
Total participation means that every entity in the entity setparticipates in at least one relationship in the relationship set.
e.g. every loan must be belong to at least one customer
customer
idname
street
city
loan
loan-number
amount
borrower1..N 0..M
Alternative notation: customer loanborrower
Partial participation means that entities may not participate inany relationship in the set.
![Page 44: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/44.jpg)
Total Participation
Total participation means that every entity in the entity setparticipates in at least one relationship in the relationship set.
e.g. every loan must be belong to at least one customer
customer
idname
street
city
loan
loan-number
amount
borrower1..N 0..M
Alternative notation: customer loanborrower
Partial participation means that entities may not participate inany relationship in the set.
![Page 45: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/45.jpg)
Total Participation
Total participation means that every entity in the entity setparticipates in at least one relationship in the relationship set.
e.g. every loan must be belong to at least one customer
customer
idname
street
city
loan
loan-number
amount
borrower1..N 0..M
Alternative notation: customer loanborrower
Partial participation means that entities may not participate inany relationship in the set.
![Page 46: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/46.jpg)
Data Modelling :: Relationship Sets with Attributes
![Page 47: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/47.jpg)
Relationship Sets with Attributes
An attribute can also be property of a relationship set.
The plays-in relationshipset between the entity setsactor and movie may havethe attribute salary.
actor movieplays-in
salary
Uma ThurmanMark Hamill
Harrison Ford
Pulp FictionStar Wars
Indiana Jonesactor
entity setmovie
entity setplays-in(salary)relationship set
10$
5$3$ 20$
The value of the relationship attributes is functionallydetermined by the relationship (e1, . . . ,en).
![Page 48: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/48.jpg)
Relationship Sets with Attributes
An attribute can also be property of a relationship set.
The plays-in relationshipset between the entity setsactor and movie may havethe attribute salary.
actor movieplays-in
salary
Uma ThurmanMark Hamill
Harrison Ford
Pulp FictionStar Wars
Indiana Jonesactor
entity setmovie
entity setplays-in(salary)relationship set
10$
5$3$ 20$
The value of the relationship attributes is functionallydetermined by the relationship (e1, . . . ,en).
![Page 49: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/49.jpg)
Relationship Sets with Attributes
An attribute can also be property of a relationship set.
The plays-in relationshipset between the entity setsactor and movie may havethe attribute salary.
actor movieplays-in
salary
Uma ThurmanMark Hamill
Harrison Ford
Pulp FictionStar Wars
Indiana Jonesactor
entity setmovie
entity setplays-in(salary)relationship set
10$
5$3$ 20$
The value of the relationship attributes is functionallydetermined by the relationship (e1, . . . ,en).
![Page 50: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/50.jpg)
Relationship Sets with Attributes
Consequences of the semantics
cinema movieshows
time
Suppose a cinema shows a movie twice a day (at 3pm and 6pm).
Can this information be stored in the given schema?
![Page 51: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/51.jpg)
Cardinalities affect the ER Design
customer
idname
street
city
account
account-number
balance
depositor
Assume that we want to record the date of the last access of acustomer to an account. We call this attribute access-date.
If the relation from customer to account is many-to-many:then access-date must be an attribute of depositor
If the relation from customer to account is one-to-many:then access-date can be an attribute of account
![Page 52: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/52.jpg)
Cardinalities affect the ER Design
customer
idname
street
city
account
account-number
balance
depositor
Assume that we want to record the date of the last access of acustomer to an account. We call this attribute access-date.
If the relation from customer to account is many-to-many:then access-date must be an attribute of depositor
If the relation from customer to account is one-to-many:then access-date can be an attribute of account
![Page 53: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/53.jpg)
Data Modelling :: Weak Entity Sets
![Page 54: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/54.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
There can be multiple payments with equal payment-number
the payment-number is not a key
payments must always be associated to precisely one loan
the payment-number identifies a payment uniquely onlyin combination with the loan-number of the associated loan
In other words, the discriminator payment-number is uniqueamong all payments for a certain loan.
![Page 55: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/55.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
There can be multiple payments with equal payment-number
the payment-number is not a key
payments must always be associated to precisely one loan
the payment-number identifies a payment uniquely onlyin combination with the loan-number of the associated loan
In other words, the discriminator payment-number is uniqueamong all payments for a certain loan.
![Page 56: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/56.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
There can be multiple payments with equal payment-number
the payment-number is not a key
payments must always be associated to precisely one loan
the payment-number identifies a payment uniquely onlyin combination with the loan-number of the associated loan
In other words, the discriminator payment-number is uniqueamong all payments for a certain loan.
![Page 57: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/57.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
There can be multiple payments with equal payment-number
the payment-number is not a key
payments must always be associated to precisely one loan
the payment-number identifies a payment uniquely onlyin combination with the loan-number of the associated loan
In other words, the discriminator payment-number is uniqueamong all payments for a certain loan.
![Page 58: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/58.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
A weak entity set is an entity set without a primary key.
The existence of a weak entity set depends on theexistence of an identifying entity set.There must be a total, one-to-many relationship set fromthe identifying entity set to the weak entity set. Thisidentifying relationship is depicted by a double diamond.The discriminator is a partial key, it distinguishes theweak entity only in combination with the identifying entity.Primary key of the weak entity set is a combination of thediscriminator and primary key of the identifying entity set.
![Page 59: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/59.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
A weak entity set is an entity set without a primary key.The existence of a weak entity set depends on theexistence of an identifying entity set.
There must be a total, one-to-many relationship set fromthe identifying entity set to the weak entity set. Thisidentifying relationship is depicted by a double diamond.The discriminator is a partial key, it distinguishes theweak entity only in combination with the identifying entity.Primary key of the weak entity set is a combination of thediscriminator and primary key of the identifying entity set.
![Page 60: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/60.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
A weak entity set is an entity set without a primary key.The existence of a weak entity set depends on theexistence of an identifying entity set.There must be a total, one-to-many relationship set fromthe identifying entity set to the weak entity set. Thisidentifying relationship is depicted by a double diamond.
The discriminator is a partial key, it distinguishes theweak entity only in combination with the identifying entity.Primary key of the weak entity set is a combination of thediscriminator and primary key of the identifying entity set.
![Page 61: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/61.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
A weak entity set is an entity set without a primary key.The existence of a weak entity set depends on theexistence of an identifying entity set.There must be a total, one-to-many relationship set fromthe identifying entity set to the weak entity set. Thisidentifying relationship is depicted by a double diamond.The discriminator is a partial key, it distinguishes theweak entity only in combination with the identifying entity.
Primary key of the weak entity set is a combination of thediscriminator and primary key of the identifying entity set.
![Page 62: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/62.jpg)
Weak Entity Sets
loan
loan-number
loan-amount
payment
payment-number
date amount
loanpayment
1..1 0..∗
A weak entity set is an entity set without a primary key.The existence of a weak entity set depends on theexistence of an identifying entity set.There must be a total, one-to-many relationship set fromthe identifying entity set to the weak entity set. Thisidentifying relationship is depicted by a double diamond.The discriminator is a partial key, it distinguishes theweak entity only in combination with the identifying entity.Primary key of the weak entity set is a combination of thediscriminator and primary key of the identifying entity set.
![Page 63: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/63.jpg)
Weak Entity Sets
Modelling with Weak Entity SetsModel a set of online quizzes (multiple-choice tests).
each quiz is identified by a titleeach question within a quiz is numberedeach possible answer to a question is referenced by a letterfor each question and answer the associated text is storedanswers are classified into correct and incorrect ones
Develop an ER diagram.
What is the complete key for each of the entity sets?
![Page 64: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/64.jpg)
Data Modelling :: IS-A, ‘Inheritance’
![Page 65: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/65.jpg)
IS-A, ‘Inheritance’
person
name address
employee
salary
customer
credit-ratingISA
officer
office-number
teller
station-number hours-worked
secretary
hours-worked
ISA
![Page 66: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/66.jpg)
IS-A, ‘Inheritance’
person
name address
employee
salary
customer
ISA
Lower-level entity sets are subgroupsof the of higher-level entity sets:
e.g. an employee ‘is a’ person
Lower-level entity sets inherit allattributes and relationship sets ofthe higher-level entity sets.
e.g. an employee has attributesname, address and salary
Design Principle: Specialisationtop-down design processidentify subgroups within an entity setthese subgroups become lower-level entity sets which mayhave attributes or participate in relationship sets that donot apply to the higher-level entity sets
![Page 67: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/67.jpg)
IS-A, ‘Inheritance’
person
name address
employee
salary
customer
ISA
Lower-level entity sets are subgroupsof the of higher-level entity sets:
e.g. an employee ‘is a’ person
Lower-level entity sets inherit allattributes and relationship sets ofthe higher-level entity sets.
e.g. an employee has attributesname, address and salary
Design Principle: Specialisationtop-down design processidentify subgroups within an entity setthese subgroups become lower-level entity sets which mayhave attributes or participate in relationship sets that donot apply to the higher-level entity sets
![Page 68: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/68.jpg)
IS-A, ‘Inheritance’
person
name address
employee
salary
customer
ISA
Lower-level entity sets are subgroupsof the of higher-level entity sets:
e.g. an employee ‘is a’ person
Lower-level entity sets inherit allattributes and relationship sets ofthe higher-level entity sets.
e.g. an employee has attributesname, address and salary
Design Principle: Specialisationtop-down design processidentify subgroups within an entity setthese subgroups become lower-level entity sets which mayhave attributes or participate in relationship sets that donot apply to the higher-level entity sets
![Page 69: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/69.jpg)
IS-A, ‘Inheritance’
person
name address
employee
salary
customer
ISA
Lower-level entity sets are subgroupsof the of higher-level entity sets:
e.g. an employee ‘is a’ person
Lower-level entity sets inherit allattributes and relationship sets ofthe higher-level entity sets.
e.g. an employee has attributesname, address and salary
Design Principle: Generalisationbottom-up design processcombine a number of entity sets that share commonfeatures into a higher-level entity set
specialisation and generalisation are both ‘is a’-relations
![Page 70: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/70.jpg)
IS-A, ‘Inheritance’
Membership constraintsvalue-based: assigns an entity to a spe-cific subclass based on attribute valuese.g. a person of age ≥ 18 is an adult
ISAage≥ 18
default is user-defined: manual assignment to subclasses
Disjointness constraintsdisjoint: an entity can belong to at mostone subclass; e.g. a fruit can be an appleor a pear, but not both
ISA
disjoint
default is overlapping: can belong to multiple subclasses
Completeness constraintstotal specialisation (generalisation)constraint: each superclass entity mustbelong to a subclass; e.g. a person iseither a minor or an adult
ISA
![Page 71: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/71.jpg)
IS-A, ‘Inheritance’
Membership constraintsvalue-based: assigns an entity to a spe-cific subclass based on attribute valuese.g. a person of age ≥ 18 is an adult
ISAage≥ 18
default is user-defined: manual assignment to subclasses
Disjointness constraintsdisjoint: an entity can belong to at mostone subclass; e.g. a fruit can be an appleor a pear, but not both
ISA
disjoint
default is overlapping: can belong to multiple subclasses
Completeness constraintstotal specialisation (generalisation)constraint: each superclass entity mustbelong to a subclass; e.g. a person iseither a minor or an adult
ISA
![Page 72: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/72.jpg)
IS-A, ‘Inheritance’
Membership constraintsvalue-based: assigns an entity to a spe-cific subclass based on attribute valuese.g. a person of age ≥ 18 is an adult
ISAage≥ 18
default is user-defined: manual assignment to subclasses
Disjointness constraintsdisjoint: an entity can belong to at mostone subclass; e.g. a fruit can be an appleor a pear, but not both
ISA
disjoint
default is overlapping: can belong to multiple subclasses
Completeness constraintstotal specialisation (generalisation)constraint: each superclass entity mustbelong to a subclass; e.g. a person iseither a minor or an adult
ISA
![Page 73: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/73.jpg)
Data Modelling :: Aggregation
![Page 74: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/74.jpg)
Aggregation
Consider the works-on relation we have seen before.
We now want to express that a task performed by an employeemight have a manager assigned to it.
ER model has no relations between relations
employee branch
job
works-on
manager manages
![Page 75: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/75.jpg)
Aggregation
Consider the works-on relation we have seen before.
We now want to express that a task performed by an employeemight have a manager assigned to it.
ER model has no relations between relations
employee branch
job
works-on
manager manages
![Page 76: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/76.jpg)
Aggregation
Consider the works-on relation we have seen before.
We now want to express that a task performed by an employeemight have a manager assigned to it.
ER model has no relations between relations
employee branch
job
works-on
manager manages
![Page 77: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/77.jpg)
Aggregation
Consider the works-on relation we have seen before.
We now want to express that a task performed by an employeemight have a manager assigned to it.
ER model has no relations between relations
employee branch
job
works-on
manager manages
![Page 78: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/78.jpg)
Aggregation
employee branch
job
works-on
manager manages
However, this design is not good:does not capture: every manages relationshipcorresponds to a works-on relationship;information is represented redundant/overlapping;we cannot discard the works-on relationship set: someworks-on relationships may not correspond to anymanages relationship.
The solution is to eliminate redundancy using aggregation!
![Page 79: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/79.jpg)
Aggregation
employee branch
job
works-on
manager manages
However, this design is not good:
does not capture: every manages relationshipcorresponds to a works-on relationship;information is represented redundant/overlapping;we cannot discard the works-on relationship set: someworks-on relationships may not correspond to anymanages relationship.
The solution is to eliminate redundancy using aggregation!
![Page 80: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/80.jpg)
Aggregation
employee branch
job
works-on
manager manages
However, this design is not good:does not capture: every manages relationshipcorresponds to a works-on relationship;information is represented redundant/overlapping;we cannot discard the works-on relationship set: someworks-on relationships may not correspond to anymanages relationship.
The solution is to eliminate redundancy using aggregation!
![Page 81: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/81.jpg)
Aggregation
employee branch
job
works-on
manager manages
However, this design is not good:does not capture: every manages relationshipcorresponds to a works-on relationship;information is represented redundant/overlapping;we cannot discard the works-on relationship set: someworks-on relationships may not correspond to anymanages relationship.
The solution is to eliminate redundancy using aggregation!
![Page 82: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/82.jpg)
Aggregation
Aggregation:treat relationship set as an abstract entryabstraction of a relationship into a new entry
allows relations between relations
employee branch
job
works-on
manager
manages
![Page 83: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/83.jpg)
Data Modelling :: Notation Summary
![Page 84: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/84.jpg)
Entity-Relationship Models Summary
E entity set A attribute
E weak entity set A multi-valued attribute
R relationship set A derived attribute
Ridentifyingrelationship setfor weak entity set
R Etotal participationof entity setin relationship
A primary key Adiscriminatingattribute ofweak entity set
![Page 85: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/85.jpg)
Entity-Relationship Models Summary
Rmany-to-manyrelationship R
many-to-onerelationship
Rone-to-onerelationship R E
M..N cardinalitylimits
R E
rolename role
indicatorISA
ISA(generalisationor specialisation)
ISA totalgeneralisation
ISA
disjoint
disjointgeneralisation
![Page 86: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/86.jpg)
Data Modelling :: Unified Modelling Language
![Page 87: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/87.jpg)
Unified Modelling Language
UML = Unified Modeling Language
Example schema as UML class diagram
1..1 0..*
customer
+id+name+street+city
account
+account-number+balance
deposits .
/ depositor
UML diagrams are similar to ER diagramsHowever, there are important differences!
![Page 88: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/88.jpg)
Unified Modelling Language
UML = Unified Modeling Language
Example schema as UML class diagram
1..1 0..*
customer
+id+name+street+city
account
+account-number+balance
deposits .
/ depositor
UML diagrams are similar to ER diagramsHowever, there are important differences!
![Page 89: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/89.jpg)
ER Models vs. UML Class Diagrams
Entity Sets and Attributes
customer
idname
street
city
customer
+id <<PK>>+name+street+city
In UML attributes are shown within the box of the entity setrather than as separate ellipses in ER models.
![Page 90: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/90.jpg)
ER Models vs. UML Class Diagrams
Binary Relationships
RE1 role1 E2role2 role1 role2E1
. . .
E2
. . .R
In UML binary relationship sets are represented by a lineconnecting the entity sets. The name of the relationshipset is written adjacent to the line.
![Page 91: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/91.jpg)
ER Models vs. UML Class Diagrams
Binary Relationships with Attributes
RE1 role1 E2role2
a1 a2
role1 role2E1
. . .
E2
. . .
R
a1a2
If the relationship set has attributes, then the name of therelationship set is written in a box together with theattributes of the relation.The box is then connected using a dashed line to the linecorresponding to the relationship set.
![Page 92: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/92.jpg)
ER Models vs. UML Class Diagrams
Non-Binary Relationships
RE1 E2
E3
E1
. . .
E2
. . .
E3
. . .
R
Non-binary relationship sets are drawn using a diamond.
![Page 93: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/93.jpg)
ER Models vs. UML Class Diagrams
Generalisation and Specialisation
person
employee customer
ISA
employee customer
person
overlapping
person
employee customer
ISAdisjoint
employee customer
person
disjoint
![Page 94: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/94.jpg)
ER Models vs. UML Class Diagrams
Cardinality Limits
RE1M1..M2 E2
N1..N2M1..M2 N1..N2
E1
. . .
E2
. . .R
The cardinalities indicate that:each E2 entity is related to ≥ M1 and ≤ M2 entities in E1
each E1 entity is related to ≥ N1 and ≤ N2 entities in E2
In UML we have the following abbreviations:1 stands for 1..1∗ stands for 0..∗
Often better to write fully 1..1 and 0..∗.
![Page 95: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/95.jpg)
ER Models vs. UML Class Diagrams
Cardinality Limits
RE1M1..M2 E2
N1..N2M1..M2 N1..N2
E1
. . .
E2
. . .R
The cardinalities indicate that:each E2 entity is related to ≥ M1 and ≤ M2 entities in E1
each E1 entity is related to ≥ N1 and ≤ N2 entities in E2
In UML we have the following abbreviations:1 stands for 1..1∗ stands for 0..∗
Often better to write fully 1..1 and 0..∗.
![Page 96: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/96.jpg)
UML: Aggregation and Composition
Aggregation in UML
1..∗system
+name+location
component
+type+model+ serialNumber
Aggregation: system is a collection of components
Composition: if the diamond would be filled black, it wouldmean that every component belongs to one system (1..1)
It is important to note the difference with ER models:In ER aggregation allows to treat relations as entities.Composition in UML is similar to weak entities in ER.However, composition in UML says nothing about keys.
![Page 97: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/97.jpg)
UML: Aggregation and Composition
Aggregation in UML
1..∗system
+name+location
component
+type+model+ serialNumber
Aggregation: system is a collection of components
Composition: if the diamond would be filled black, it wouldmean that every component belongs to one system (1..1)
It is important to note the difference with ER models:In ER aggregation allows to treat relations as entities.Composition in UML is similar to weak entities in ER.However, composition in UML says nothing about keys.
![Page 98: Databases – Data Modellingjoerg.endrullis.de/databases/02_data_modelling.pdf/02_data_modelli… · Cardinality Limits Cardinality limits express the number of entities to which](https://reader035.fdocuments.us/reader035/viewer/2022071302/60aac970068a167c4c7d88bd/html5/thumbnails/98.jpg)
Differences: ER Models vs. UML Class Diagrams
visual differences — no big deal
keys:ER supports keys (underlining)UML has no standard for indicating keysSome people underline, others write PK after the attribute.
aggregation: means something very differentin ER: treating a relationship set as an entityin UML: a part-whole relation(non-exclusive form of composition)
weak entities:in ER: weak entities are entities without own keyin UML: composition is similar, but says nothing about keys