“Database Management Systems”
CS-222
Lecture 33
“Cardinality & modality”
Dr. Muhammad Muneer Umar
By:
Lecturer in Computer Science
Institute of Computing
KUST, Pakistan
Consider some cases
• An employee can have many children
• A student must have exactly one father
• Many teachers are teaching many subjects
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Agenda
• Revision of ERD
• Cardinality and Modality
• How to read cardinalities
• Sample Cases
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
-Semantic Data Model
-Graphical representation of the conceptual
database design
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
ERD ( Entity Relationship Diagram)
-Semantic Data Model
-Graphical representation of the conceptual
database design
Three major constructs:
1.Entity
2.Attributes
3.Relationships
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
ERD ( Entity Relationship Diagram)
Entity
Entity
Type
Entity
Instance
Entity
Set
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
STUDENT LOCATION
1.Entity-Entity Type
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
STUDENT LOCATION
Name … ZIP
Ali --- 26000
Ahmed --- 25000
ZIP City Province Country
26000 Kohat KPK Pakistan
25000 Peshawar KPK Pakistan
41000 Islamabad Pakistan
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
1.Entity-Entity Instance & Set
STUDENT
2. Attributes
Name
FName
Age
Skills
Skills
Session
Start End
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
STUDENT LOCATION
Name … ZIP
Ali --- 26000
Ahmed --- 25000
Khan --- 26000
ZIP City Province Country
26000 Kohat KPK Pakistan
25000 Peshawar KPK Pakistan
54000 Lahore Punjab Pakistan
72206 Tehran Tehran Iran
3. Relationships
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
STUDENT LOCATION
Name … ZIP
Ali --- 26000
Ahmed --- 25000
Khan --- 26000
ZIP City Province Country
26000 Kohat KPK Pakistan
25000 Peshawar KPK Pakistan
54000 Lahore Punjab Pakistan
72206 Tehran Tehran Iran
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
3. Relationships
Agenda
• Revision of ERD
• Cardinality and Modality
• How to read cardinalities
• Sample Cases
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Cardinality  Maximum possible
associations
1 OR many
Modality  Minimum possible
associations
1 OR Zero
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
STUDENT LOCATION
Name … ZIP
Ali --- 26000
Ahmed --- 25000
Khan --- 26000
ZIP City Province Country
26000 Kohat KPK Pakistan
25000 Peshawar KPK Pakistan
54000 Lahore Punjab Pakistan
72206 Tehran Tehran Iran
Modality
Cardinality
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Cardinality and Modality
Cardinality and Modality work together to define the relationship
• Cardinality indicates the maximum number of times an
instance in one entity can be associated with instances in the
related entity
• Modality indicates the minimum number of times an instance
in one entity can be associated with an instance in the related
entity
• Cardinality and Modality are both shown on the relationship
line by symbols
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Agenda
• Revision of ERD
• Cardinality and Modality
• How to read cardinalities
• Sample Cases
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Reading Modality and Cardinality
from Zero to Many
from One to Many
from One to One
i.e., one and only one
from Zero to One
Modality and cardinality are combined (two at a time)
in these ways:
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Student
Seat
fills
Course
Instructor teaches
Course
Student Registers
for
Transcript
Student
has
Left to right: a seat is filled by exactly one student
Right to left: a student fills exactly one seat
Left to right: a student has one or more transcripts
Right to left: a transcript has one student
Left to right: a student registers for one or more courses
Right to left: a course is registered by one or more students
Left to right: an instructor teaches zero to many courses
Right to left: a course is taught by exactly one instructor
Reading Cardinality and Modality
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Student
Seat
fills
Course
Instructor teaches
Course
Student Registers
for
Left to right: one to one, 1:1
Right to left: one to one, 1:1
Left to right: one to many, 1:M
Right to left: many to one, M:1
Left to right: many to many, M:M
Right to left: many to many, M:M
Left to right: one to many, 1:M
Right to left: many to one, M:1
Reading Cardinality
Transcript
Student
has
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Cardinalities and Modalities
•Modalities can also be called as:
•Mandatory Cardinalities = The entity must
participate in another entity.
•Optional Cardinalities = The entity has the
option to participate in another entity.
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Cardinalities and Modalities
•Cardinalities and modalities can also be
defined as:
•Maximum Cardinality: One or many
•Minimum Cardinality: Required or not.
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
Agenda
• Revision of ERD
• Cardinality and Modality
• How to read cardinalities
• Sample Cases
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
EMPLOYEE VEHICLE
Name … VID
Ali --- IDE403
Ahmed ---
Khan --- EGA911
Akbar CSS900
Burhan ACX907
VID Type Model Maker
IDE403 Sedan 2017 Toyota
ACX907 Hatchback 2013 Suzuki
EGA911 SUV 2009 Toyota
CSS900 Sedan 2011 Toyota
Is it Correct??
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
EMPLOYEE VEHICLE
Name … VID
Ali --- IDE403
Ahmed ---
Khan --- EGA911
Akbar CSS900
Burhan ACX907
VID Type Model Maker
IDE403 Sedan 2017 Toyota
ACX907 Hatchback 2013 Suzuki
EGA911 SUV 2009 Toyota
CSS900 Sedan 2011 Toyota
Now it is Correct 
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
EMPLOYEE CHILDREN
Name … CID
Ali --- C001
Ali --- C002
Khan --- C003
Akbar
Burhan C004
CID NAME ---
C001 Asad
C002 Ayesha
C003 Farooq
C004 Khalil
???
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
EMPLOYEE CHILDREN
Name … CID
Ali --- C001
Ali --- C002
Khan --- C003
Akbar
Burhan C004
CID NAME ---
C001 Asad
C002 Ayesha
C003 Farooq
C004 Khalil
???
Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk
Topic: Cardinality & Modality
SUMMARY
• REVISION OF ERD
• Cardinality  Maximum cases (1 or many)
• Modality  Minimum Cases (0 or 1)
• Mandatory Cardinality  Modality =1
• Optional Cardinality  Modality = 0
• Possible Cases  1:1, 1:M, M:M (can be read from both direction)
Thank You
•You any query post your comment on KCMS.

Lecture 7 (Week 7) - Cardinality & modality.pptx

  • 1.
    “Database Management Systems” CS-222 Lecture33 “Cardinality & modality” Dr. Muhammad Muneer Umar By: Lecturer in Computer Science Institute of Computing KUST, Pakistan
  • 2.
    Consider some cases •An employee can have many children • A student must have exactly one father • Many teachers are teaching many subjects Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 3.
    Agenda • Revision ofERD • Cardinality and Modality • How to read cardinalities • Sample Cases Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 4.
    -Semantic Data Model -Graphicalrepresentation of the conceptual database design Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality ERD ( Entity Relationship Diagram)
  • 5.
    -Semantic Data Model -Graphicalrepresentation of the conceptual database design Three major constructs: 1.Entity 2.Attributes 3.Relationships Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality ERD ( Entity Relationship Diagram)
  • 6.
    Entity Entity Type Entity Instance Entity Set Course: Database ManagementSystems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 7.
    STUDENT LOCATION 1.Entity-Entity Type Course:Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 8.
    STUDENT LOCATION Name …ZIP Ali --- 26000 Ahmed --- 25000 ZIP City Province Country 26000 Kohat KPK Pakistan 25000 Peshawar KPK Pakistan 41000 Islamabad Pakistan Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality 1.Entity-Entity Instance & Set
  • 9.
    STUDENT 2. Attributes Name FName Age Skills Skills Session Start End Course:Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 10.
    STUDENT LOCATION Name …ZIP Ali --- 26000 Ahmed --- 25000 Khan --- 26000 ZIP City Province Country 26000 Kohat KPK Pakistan 25000 Peshawar KPK Pakistan 54000 Lahore Punjab Pakistan 72206 Tehran Tehran Iran 3. Relationships Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 11.
    STUDENT LOCATION Name …ZIP Ali --- 26000 Ahmed --- 25000 Khan --- 26000 ZIP City Province Country 26000 Kohat KPK Pakistan 25000 Peshawar KPK Pakistan 54000 Lahore Punjab Pakistan 72206 Tehran Tehran Iran Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality 3. Relationships
  • 12.
    Agenda • Revision ofERD • Cardinality and Modality • How to read cardinalities • Sample Cases Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 13.
    Cardinality  Maximumpossible associations 1 OR many Modality  Minimum possible associations 1 OR Zero Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 14.
    STUDENT LOCATION Name …ZIP Ali --- 26000 Ahmed --- 25000 Khan --- 26000 ZIP City Province Country 26000 Kohat KPK Pakistan 25000 Peshawar KPK Pakistan 54000 Lahore Punjab Pakistan 72206 Tehran Tehran Iran Modality Cardinality Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 15.
    Cardinality and Modality Cardinalityand Modality work together to define the relationship • Cardinality indicates the maximum number of times an instance in one entity can be associated with instances in the related entity • Modality indicates the minimum number of times an instance in one entity can be associated with an instance in the related entity • Cardinality and Modality are both shown on the relationship line by symbols Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 16.
    Agenda • Revision ofERD • Cardinality and Modality • How to read cardinalities • Sample Cases Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 17.
    Reading Modality andCardinality from Zero to Many from One to Many from One to One i.e., one and only one from Zero to One Modality and cardinality are combined (two at a time) in these ways: Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 18.
    Student Seat fills Course Instructor teaches Course Student Registers for Transcript Student has Leftto right: a seat is filled by exactly one student Right to left: a student fills exactly one seat Left to right: a student has one or more transcripts Right to left: a transcript has one student Left to right: a student registers for one or more courses Right to left: a course is registered by one or more students Left to right: an instructor teaches zero to many courses Right to left: a course is taught by exactly one instructor Reading Cardinality and Modality Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 19.
    Student Seat fills Course Instructor teaches Course Student Registers for Leftto right: one to one, 1:1 Right to left: one to one, 1:1 Left to right: one to many, 1:M Right to left: many to one, M:1 Left to right: many to many, M:M Right to left: many to many, M:M Left to right: one to many, 1:M Right to left: many to one, M:1 Reading Cardinality Transcript Student has Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 20.
    Cardinalities and Modalities •Modalitiescan also be called as: •Mandatory Cardinalities = The entity must participate in another entity. •Optional Cardinalities = The entity has the option to participate in another entity. Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 21.
    Cardinalities and Modalities •Cardinalitiesand modalities can also be defined as: •Maximum Cardinality: One or many •Minimum Cardinality: Required or not. Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 22.
    Agenda • Revision ofERD • Cardinality and Modality • How to read cardinalities • Sample Cases Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 23.
    EMPLOYEE VEHICLE Name …VID Ali --- IDE403 Ahmed --- Khan --- EGA911 Akbar CSS900 Burhan ACX907 VID Type Model Maker IDE403 Sedan 2017 Toyota ACX907 Hatchback 2013 Suzuki EGA911 SUV 2009 Toyota CSS900 Sedan 2011 Toyota Is it Correct?? Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 24.
    EMPLOYEE VEHICLE Name …VID Ali --- IDE403 Ahmed --- Khan --- EGA911 Akbar CSS900 Burhan ACX907 VID Type Model Maker IDE403 Sedan 2017 Toyota ACX907 Hatchback 2013 Suzuki EGA911 SUV 2009 Toyota CSS900 Sedan 2011 Toyota Now it is Correct  Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 25.
    EMPLOYEE CHILDREN Name …CID Ali --- C001 Ali --- C002 Khan --- C003 Akbar Burhan C004 CID NAME --- C001 Asad C002 Ayesha C003 Farooq C004 Khalil ??? Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 26.
    EMPLOYEE CHILDREN Name …CID Ali --- C001 Ali --- C002 Khan --- C003 Akbar Burhan C004 CID NAME --- C001 Asad C002 Ayesha C003 Farooq C004 Khalil ??? Course: Database Management Systems (CS222) || Instructor: Dr. Muneer Umar, Lecturer. Institute of Computing, KUST || Email: muneer.umar@kust.edu.pk Topic: Cardinality & Modality
  • 27.
    SUMMARY • REVISION OFERD • Cardinality  Maximum cases (1 or many) • Modality  Minimum Cases (0 or 1) • Mandatory Cardinality  Modality =1 • Optional Cardinality  Modality = 0 • Possible Cases  1:1, 1:M, M:M (can be read from both direction)
  • 28.
    Thank You •You anyquery post your comment on KCMS.