Fundamentals of Database Systems
1
Lecture 8: Data Modeling Using the Entity-Relationship
Model (Part 3).
Quick Review of
Lecture 7
2
Relationship
• association between two (or more) entities
• relationships represented by diamond
Examples
• Students Register for Subjects
• School Has Staff
• Driver Commits Traffic Offence
• Customer Orders Product
• Supplier Supplies Parts To Projects
3
ENTITY Relationship ENTITY
attribute
attribute
primary key
Attributes of Relationship Types
Relationship types can also have attributes.
• E.g. customer orders a product
• quantity is attribute of orders relationship
• E.g. Employee WORKS-ON Project
• To record the number of hours per week that an employee works
on a particular project. The attribute Hours can be included to the
WORKS-ON relationship type.
4
customer product
orders
quantity
Employee Project
works-on
Hours
UNARY : One entity set, recursive.
BINARY : Two entity sets linked (mostly used).
TERNARY :Three entity sets linked.
SUBJECT prerequisite
N
M
STUDENT SUBJECT
enrols in
M N
RENTAL SHOP VIDEO
owns
M N
BORROWER
1
Examples of Relationship
5
More Examples
6
End of Review
7
Constraints on Relationships
• There are three types of relationship constraints:
• Cardinality ratio.
• Participation.
• Multiplicity.
8
Relationship Relationship
1 M
(1,*) (1,*)
Cardinality Ratio
Cardinality ratio Express the number of relationship an entity can
participate in.
Relationships can be classified as :
one-to-one (1:1)
one-to-many (1:M)
Many-to-one (M:1)
many-to-many (M:N)
9
One-to-one Relationship (1:1)
Professor Manage Department
P1 r1 D001
P2
P3 r2 D002
Each professor manages at most one department; and each
department is managed by only one professor 10
Professor Department
Manage
1
1
One-to-Many Relationship (1:M)
Professor teach Section
P1 r1 3C01
r2 3C03
P2 r3 3C02
Each professor teaches many sections; but each section is
taught by only one professor (or at most one professor) 11
Professor Section
teach
M
1
Many-to-One Relationship (M:1)
Professor work-in Department
P1 r1 Com. Science
P2 r2 Network
P3 r3 Info. Sys
Each professor works in only one Department; but each
Department has many professors (many professors work in one
department)
12
Professor Department
Work-in
1
M
Many-to-Many Relationship
Student Enroll-in Course
S1 r1 is300
S2 r2 is400
S3 r3 is500
S4 r4 is600
Each student can enroll in many courses; and each course can be
enrolled by many students. 13
Student course
Enroll-in
M
M
Multiplicity
Multiplicity is the number (range) of possible entities that
may relate to a single association through a particular
relationship
• Takes the form (min#, max#)
14
Professor Manage Department
P1 r1 D001
P2
P3 r2 D002
• Each Professor may manage 0 to 1 department,
• Each Department should be managed by only one Professor .
Multiplicity
15
Professor Department
manage
(0,1) (1,1)
1 1
Multiplicity
Professor teach Section
P1 r1 3C01
P2 r2 3C03
P3 r3 3C02
• Each Professor may teach 0 to 5 Sections,
• Each Section should be taught by only one Professor .
• * = many .. Use it if the number is not specified 16
Professor Section
teach
M
1
(0,5) (1,1)
(0,*)
Multiplicity
Student Enroll-in Course
S1 r1 is300
S2 r2 is400
S3 r3 is500
S4 r4 is600
• Each student should enroll in 1 to 7 Courses,
• Each Course may be enrolled by 0 to 100 students.
• * = many .. Use it if the number is not specified 17
Student Course
Enroll-in
M
M
(1,7) (0,100)
(1,*) (0,*)
Participation
• Participation constraints determine whether all or only some
entities participate in a relationship.
• Two type of participation:
• Mandatory (Total)
• Optional (Partial)
18
Participation
• Optional (partial) (0:*)
• eg, an employee may not have a spouse
• not every staff manages a department
• Partial participation is represented by single line
• Mandatory (total) (1:*)
• eg, every spouse must be that of an employee
• Every department is managed by some staff.
• Mandatory participation is represented by double line
19
R E
R E
Examples
20
Employee Spouse
1 1
has
(0,M) (1,1)
(1:M) (0:N)
Order
Customer place
Subject
Student enrol
1 N
M N
21

lecture 8 Data Modeling Using the Entity-Relationship Model (3).pptx

  • 1.
    Fundamentals of DatabaseSystems 1 Lecture 8: Data Modeling Using the Entity-Relationship Model (Part 3).
  • 2.
  • 3.
    Relationship • association betweentwo (or more) entities • relationships represented by diamond Examples • Students Register for Subjects • School Has Staff • Driver Commits Traffic Offence • Customer Orders Product • Supplier Supplies Parts To Projects 3 ENTITY Relationship ENTITY attribute attribute primary key
  • 4.
    Attributes of RelationshipTypes Relationship types can also have attributes. • E.g. customer orders a product • quantity is attribute of orders relationship • E.g. Employee WORKS-ON Project • To record the number of hours per week that an employee works on a particular project. The attribute Hours can be included to the WORKS-ON relationship type. 4 customer product orders quantity Employee Project works-on Hours
  • 5.
    UNARY : Oneentity set, recursive. BINARY : Two entity sets linked (mostly used). TERNARY :Three entity sets linked. SUBJECT prerequisite N M STUDENT SUBJECT enrols in M N RENTAL SHOP VIDEO owns M N BORROWER 1 Examples of Relationship 5
  • 6.
  • 7.
  • 8.
    Constraints on Relationships •There are three types of relationship constraints: • Cardinality ratio. • Participation. • Multiplicity. 8 Relationship Relationship 1 M (1,*) (1,*)
  • 9.
    Cardinality Ratio Cardinality ratioExpress the number of relationship an entity can participate in. Relationships can be classified as : one-to-one (1:1) one-to-many (1:M) Many-to-one (M:1) many-to-many (M:N) 9
  • 10.
    One-to-one Relationship (1:1) ProfessorManage Department P1 r1 D001 P2 P3 r2 D002 Each professor manages at most one department; and each department is managed by only one professor 10 Professor Department Manage 1 1
  • 11.
    One-to-Many Relationship (1:M) Professorteach Section P1 r1 3C01 r2 3C03 P2 r3 3C02 Each professor teaches many sections; but each section is taught by only one professor (or at most one professor) 11 Professor Section teach M 1
  • 12.
    Many-to-One Relationship (M:1) Professorwork-in Department P1 r1 Com. Science P2 r2 Network P3 r3 Info. Sys Each professor works in only one Department; but each Department has many professors (many professors work in one department) 12 Professor Department Work-in 1 M
  • 13.
    Many-to-Many Relationship Student Enroll-inCourse S1 r1 is300 S2 r2 is400 S3 r3 is500 S4 r4 is600 Each student can enroll in many courses; and each course can be enrolled by many students. 13 Student course Enroll-in M M
  • 14.
    Multiplicity Multiplicity is thenumber (range) of possible entities that may relate to a single association through a particular relationship • Takes the form (min#, max#) 14
  • 15.
    Professor Manage Department P1r1 D001 P2 P3 r2 D002 • Each Professor may manage 0 to 1 department, • Each Department should be managed by only one Professor . Multiplicity 15 Professor Department manage (0,1) (1,1) 1 1
  • 16.
    Multiplicity Professor teach Section P1r1 3C01 P2 r2 3C03 P3 r3 3C02 • Each Professor may teach 0 to 5 Sections, • Each Section should be taught by only one Professor . • * = many .. Use it if the number is not specified 16 Professor Section teach M 1 (0,5) (1,1) (0,*)
  • 17.
    Multiplicity Student Enroll-in Course S1r1 is300 S2 r2 is400 S3 r3 is500 S4 r4 is600 • Each student should enroll in 1 to 7 Courses, • Each Course may be enrolled by 0 to 100 students. • * = many .. Use it if the number is not specified 17 Student Course Enroll-in M M (1,7) (0,100) (1,*) (0,*)
  • 18.
    Participation • Participation constraintsdetermine whether all or only some entities participate in a relationship. • Two type of participation: • Mandatory (Total) • Optional (Partial) 18
  • 19.
    Participation • Optional (partial)(0:*) • eg, an employee may not have a spouse • not every staff manages a department • Partial participation is represented by single line • Mandatory (total) (1:*) • eg, every spouse must be that of an employee • Every department is managed by some staff. • Mandatory participation is represented by double line 19 R E R E
  • 20.
    Examples 20 Employee Spouse 1 1 has (0,M)(1,1) (1:M) (0:N) Order Customer place Subject Student enrol 1 N M N
  • 21.

Editor's Notes

  • #4 مجرم يرتكب جريمة ضابط تحقيق يحقق في جريمة سائق يرتكب مخالفة شرطي مرور يحرر مخالفة
  • #5 ولي أمر يسجل أبناءه عدد الأبناء قائد المركبة يرتكب مخالفة موقع المخالفة مجرم يرتكب جريمة وقت وقوع الجريمة