Entity Relationship model
Entity Relationship model
1
1.2: Entity-Relationship Model
• Entity sets
• Relationship sets
• Attributes
• Constraints-- Mapping Cardinalities, Participation constraints
• Keys
• Entity-relationship diagrams: Basic Structure, Mapping
Cardinality, Complex Attributes, Roles, Non binary Relationship
Sets
• Weak Entity Sets.
2
The Entity-Relationship Model
• Peter Chen proposed ER Diagram in 1971 to create a uniform
convention that can be used for relational databases and networks. He
aimed to use an ER model as a conceptual modeling approach.
• The E-R data model employs three basic concepts: entity sets,
relationship sets, and attributes. 3
Why use ER Diagrams?
4
Facts about ER Diagram Model
5
• ER diagram basically having three components:
6
7
Entity Sets
• Entity set:
8
Entity Sets
9
Relationship Sets
• A relationship is an association among two or more entities.
• When an Entity is related to another Entity, they are said to have a
relationship. For example, A Class Entity is related to Student entity,
becasue students study in classes, hence this is a relationship.
• For example, an employee works_at a department, a
student enrolls in a course. Here, Works_at and Enrolls are called
relationships.
• 2. Binary Relationship –
When there are TWO entities set participating in a relation, the
relationship is called as binary relationship.For example, Student is enrolled
in Course.
• 3. n-ary Relationship –
When there are n entities set participating in a relation, the relationship is
called as n-ary relationship. 11
Relationship Sets
12
Relationship Sets
• A relationship may also have attributes called descriptive
attributes.
14
Attributes
• An attribute describes the property of an entity. An attribute is
represented as Oval in an ER diagram.
• If a Student is an Entity, then student's roll no., student's name,
student's age, student's gender etc will be its attributes.
15
• There are four types of attributes:
1. Simple attribute:
The attributes with values that are atomic and cannot be
broken down further are simple attributes. For example, student's age, a
student's phone number is an atomic value of 10 digits.
2. Composite attribute:
A composite attribute is made up of more than one simple
attribute. For example, student's address will contain, house
no., street name, pincode etc.
16
3. Multivalued attribute:
Multivalued attributes can have more than one values. For example, a
student can have more than one mobile number, email address, etc.
In ER diagram, multivalued attribute is represented by double oval.
4. Derived attribute:
An attribute which can be derived from other attributes of the entity
type is known as derived attribute. e.g.; Age (can be derived from DOB). In ER
diagram, derived attribute is represented by dashed oval.
17
18
E-R Diagram Symbol
19
Weak Entities
• Strong Entity
• The strong entity has a primary key. Weak entities are dependent on
strong entity. Its existence is not dependent on any other entity.
• Strong Entity is represented by a single rectangle
• Weak Entity
• The weak entity in DBMS do not have a primary key and are
dependent on the parent entity. It mainly depends on other entities.
• It can be identified uniquely by considering the primary key of another
entity.
• Weak Entity is represented by double rectangle
20
• In the below ER Diagram, ‘Payment’ is the weak entity. ‘Loan Payment’ is
the identifying relationship and ‘Payment Number’ is the partial key.
Primary Key of the Loan along with the partial key would be used to
identify the records.
• Example-2:
The existence of rooms is entirely dependent on the existence of a hotel. So
room can be seen as the weak entity of the hotel.
• Example-3:
The bank account of a particular bank has no existence if the bank doesn’t
exist anymore. 21
• A loan entity can not be created for a customer if the customer doesn’t
exist
22
Mapping Cardinalities
23
Mapping cardinality
• It tells the number of entities to with another entity can be associated
through a 'relationship set' . Mapping cardinality uses binary
relationship sets.
• Different types of cardinal relationships are:
– One-to-One Relationships
– One-to-Many Relationships
– May to One Relationships
– Many-to-Many Relationships
24
1. One to One Relationship
•When a single instance of an entity is associated with a single instance
of another entity then it is called one to one relationship.
•For example, a person has only one passport and a passport is given to
one person.
25
One to Many Relationship
•When a single instance of an entity is associated with more than one
instances of another entity then it is called one to many relationship.
•For example – a customer can place many orders but a order cannot be
placed by many customers.
26
3. Many to One Relationship
•When more than one instances of an entity is associated with a single
instance of another entity then it is called many to one relationship.
•For example – many students can study in a single college but a
student cannot study in many colleges at the same time.
27
4. Many to Many Relationship
•When more than one instances of an entity is associated with more
than one instances of another entity then it is called many to many
relationship.
• For example, a can be assigned to many projects and a project can be
assigned to many students.
28
How to Create an Entity Relationship
Diagram (ERD)
29
In a university, a Student enrolls in Courses. A student must be
assigned to at least one or more Courses. Each course is taught by a
single Professor. To maintain instruction quality, a Professor can
deliver only one course
30
Step 2) Relationship Identification
We have the following two relationships
•The student is assigned a course
•Professor delivers a course
assig deliv
Student ned Course ers Professor
31
Step 3) Cardinality Identification
For them problem statement we know that,
•A student can be assigned multiple courses
•A Professor can deliver only one course
1 assig M deliv
Student ned Course ers Professor
32
Step 4) Identify Attributes:
33
Course_id Emp_id
Stud_id
1 M
assig deliv
Student ned Course ers Professor
34
• Hospital ER Model
35
• Company ER Model
36
Keys
37
Keys
• That is, a key for an entity is a set of attributes that suffice to
distinguish entities from each other.
38
Keys
student_id name phone age
1 Akon 9876723452 17
2 Akon 9991165674 19
3 Bkon 7898756543 18
4 Ckon 8987867898 19
5 Dkon 9990080080 17
Super Key
• Super Key is defined as a set of attributes within a table that can uniquely
identify each record within a table. Super Key is a superset of Candidate
key.
• In the table defined above super key would include student_id, (student_id,
name), phone etc.
39
Entity-Relationship Diagrams
40
Entity-Relationship Diagrams
Basic Structure
An E-R diagram consists of the following major components:
41
Entity-Relationship Diagrams
42
Entity-Relationship Diagrams
• Attributes that are part of the primary key are underlined.
43
Entity-Relationship Diagrams
• Consider the E-R diagram in Figure 7.7, which consists of two
entity sets, instructor and student related through a binary
relationship set advisor.
• The attributes associated with instructor are ID, name, and salary.
• The attributes associated with student are ID, name, and tot cred.
44
Entity-Relationship Diagrams
• If a relationship set has some attributes associated with it, then we
enclose the attributes in a rectangle and link the rectangle with a
dashed line to the diamond representing that relationship set.
45
Entity-Relationship Diagrams
• Mapping Cardinality
• The relationship set advisor, between the instructor and student
entity sets may be one-to-one, one-to-many, many-to-one, or
many-to-many.
46
Entity-Relationship Diagrams
• One-to-one: We draw a directed line from the relationship set
advisor to both entity sets instructor and student (see Figure 7.9a).
• This indicates that an
– instructor may advise at most one student, and
– a student may have at most one advisor.
47
Entity-Relationship Diagrams
• One-to-many: We draw a
– directed line from the relationship set advisor to the entity set
instructor and
– an undirected line to the entity set student (see Figure 7.9b).
• This indicates that an instructor may advise many students, but a
student may have at most one advisor.
48
Entity-Relationship Diagrams
• Many-to-one:
– We draw an undirected line from the relationship set advisor
to the entity set instructor and
– a directed line to the entity set student.
49
Entity-Relationship Diagrams
• Many-to-many: We draw an
– undirected line from the relationship set advisor to both entity
sets instructor and student (see Figure 7.9c).
– This indicates that an instructor may advise many students,
and a student may have many advisors.
50
Entity-Relationship Diagrams
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
References
• Disjoint example
--https://www2.cs.sfu.ca/CourseCentral/354/zaiane/material/notes/C
hapter2/node2.html
• https://searchwindowsserver.techtarget.com/definition/disjoint-
namespace
88
End of Chapter 2
89
E-R Diagram for Exercise 2.10
90
E-R Diagram for Exercise 2.15
91
E-R Diagram for Exercise 2.22
92
E-R Diagram for Exercise 2.15
93