You are on page 1of 25

CST1300 – Foundations of Informatics

Week 16 – Workshop
Entity Relationship Diagrams (ERD)
Cardinalities

Georgios A. Dafoulas
Computer Science Department
Faculty of Science and Technology
Middlesex University
Agenda

• Overview of ERD cardinalities


• From conceptual modelling to relational schema
• Converting ER model to relational model
Overview of ERD cardinalities
Overview of Cardinality in Data
Modelling

• In data modelling, cardinality refers to the relationship of data in one


database table with respect to another table.
• Two tables can be related as
– “one-to-one”
– "one-to-many”
– "many-to-many"

• A relationship may also be optional.


• Optional means that a row in one table doesn't have to relate to any row
in the other table.
– For example, not all associates are provided business credit cards; an associate may
have 0 (zero) or more credit cards issued by the company.

Source:
https://astera.zendesk.com/hc/en-us/articles/115000512603-Overview-of-Cardinality-in-Data-Modeling
Overview of Cardinality in Data
Modelling

• One:One (1:1). One row in table A relates to one row in table B.


– Using an entity-relationship (ER) model, 1:1 means that one occurrence of an entity
relates to only one occurrence in another entity.

• One:Many (1:M). One row in table A relates to many rows in table B.


– In ER modelling, 1:Many means that one occurrence in an entity relates to many
occurrences in another entity.

• Many:Many (M:N). Many rows in table A relate to many rows in table B.


– In ER terms, many occurrences in one entity relate to many occurrences in another
entity. For example, a student (table A) may sign up for many classes (table B), and a
class may have several students in it. Many-to-many relationships normally require a
cross-reference table, AB with two one-to-many relationships A:AB and B:AB

Source:
https://astera.zendesk.com/hc/en-us/articles/115000512603-Overview-of-Cardinality-in-Data-Modeling
Types of Cardinality Ratios

• Many-to-Many cardinality (m:n)

• Many-to-One cardinality (m:1)

• One-to-Many cardinality (1:n)

• One-to-One cardinality (1:1 )

Source:
https://www.gatevidyalay.com/cardinality-in-er-diagram/
Many-to-Many Cardinality

• An entity in set A can be associated with any number (zero or more) of entities
in set B.
• An entity in set B can be associated with any number (zero or more) of entities
in set A.

Symbol

Example

• One student can enrol in any number (zero or more) of courses.


• One course can be enrolled by any number (zero or more) of students.
Source:
https://www.gatevidyalay.com/cardinality-in-er-diagram/
Many-to-One Cardinality

• An entity in set A can be associated with at most one entity in set B.


• An entity in set B can be associated with any number (zero or more) of entities
in set A.

Symbol

Example

• One student can enrol in at most one course.


• One course can be enrolled by any number (zero or more) of students.
Source:
https://www.gatevidyalay.com/cardinality-in-er-diagram/
One-to-Many Cardinality

• An entity in set A can be associated with any number (zero or more) of entities
in set B.
• An entity in set B can be associated with at most one entity in set A.

Symbol

Example

• One student can enrol in any number (zero or more) of courses.


• One course can be enrolled by at most one student.
Source:
https://www.gatevidyalay.com/cardinality-in-er-diagram/
One-to-One Cardinality

• An entity in set A can be associated with at most one entity in set B.


• An entity in set B can be associated with at most one entity in set A.

Symbol

Example

• One student can enrol in at most one course.


• One course can be enrolled by at most one student.
Source:
https://www.gatevidyalay.com/cardinality-in-er-diagram/
What is Mapping Cardinality in ER
diagram || Types of mapping
cardinalities in DBMS


Play video

Source:
https://www.youtube.com/watch?v=CdGu83hrxLY
From conceptual modelling to relational
schema
Transforming conceptual model to
relational schema

• Concerning the logical design, the transformation process of conceptual


schemata into relational schemata should be performed trying to
preserve the semantics included in the conceptual schema completely.

• The final objective is to keep such semantics in the database itself and
not in those applications that access to the database.

• Nevertheless, sometimes a certain loss of semantics is produced, for


instance, foreign key and not null options in the relational model are not
sufficient to control relationship cardinality constraints.

Source:
http://what-when-how.com/information-science-and-technology/relationship-cardinality-constraints-in-relational-database-design/
Cardinality constraint

• Cardinality constraint is one of the most important restrictions that can


be established in a relationship, and in general, in a conceptual schema.
• Its functionality is to limit the number of entity occurrences associated in
a relationship.
• Cardinality constraint in binary relationship summary.

Source:
http://what-when-how.com/information-science-and-technology/relationship-cardinality-constraints-in-relational-database-design/
Cardinality notations

Source:
https://stackoverflow.com/questions/4755497/single-line-with-an-arrow-mark-in-entity-relattionship-diagram
Table relationships

• One-to-One Relationships
– A key will appear only once in a related table.
– An example of a one-to-one relationship is if each employee is assigned one computer
within a company.

• One-to-many relationships
– Keys from one table will appear multiple times in a related table.

• Many-to-many relationships
– Often causes problems in practical examples of normalised databases.
– Need to break many-to-many relationships into a series of one-to-many relationships.
– The key value of one table can appear many times in a related table.
– The opposite is also true, meaning that the primary key from that second table can
also appear many times in the first table.

Source:
https://www.informit.com/articles/article.aspx?p=27281&seqNum=3
Table relationships

• One-to-One Relationships

• One-to-many relationships

• Many-to-many relationships

Source:
https://www.informit.com/articles/article.aspx?p=27281&seqNum=3
Databases: Minimum Cardinality


Play video

Source:
https://www.youtube.com/watch?v=s1SMih8XBLI
Converting ER model to relational model
Converting ER model to relational model

Binary Relationship with 1:1 cardinality with total participation of an entity


A person has 0 or 1 passport number and Passport is always owned by 1 person. So it is 1:1
cardinality with full participation constraint from Passport

Source:
https://www.geeksforgeeks.org/mapping-from-er-model-to-relational-model/
Converting ER model to relational model

Binary Relationship with 1:1 cardinality and partial participation of both


entities
A male marries 0 or 1 female and vice versa as well. So it is 1:1 cardinality with partial
participation constraint from both

Source:
https://www.geeksforgeeks.org/mapping-from-er-model-to-relational-model/
Converting ER model to relational model

Binary Relationship with n:1 cardinality


Every student can enrol only in one elective course but for an elective course there can be
more than one student

Source:
https://www.geeksforgeeks.org/mapping-from-er-model-to-relational-model/
Entity-Relationship Diagrams:
Minimum cardinalities: Order
processing example


Play video

Source:
https://www.youtube.com/watch?v=TwIbBoTUPHQ
Resources

• Overview of Cardinality in Data Modelling (https://astera.zendesk.com/hc/en-us/articles/115000512603-


Overview-of-Cardinality-in-Data-Modeling)
• Cardinality in ER Diagram (https://www.gatevidyalay.com/cardinality-in-er-diagram/)
• Relationship Cardinality Constraints in Relational Database Design
(http://what-when-how.com/information-science-and-technology/relationship-cardinality-constraints-in-
relational-database-design/)
• Types of Table Relationships (https://www.informit.com/articles/article.aspx?p=27281&seqNum=3)
• Mapping from ER Model to Relational Model (https://www.geeksforgeeks.org/mapping-from-er-model-
to-relational-model/)
Questions

?
g.dafoulas@mdx.ac.uk

You might also like