Lecture Note 3 (ER Model)
Lecture Note 3 (ER Model)
Components of ER Diagram
• Entity
• Attributes
• Relationship
Example
1 Akshay 20
2 Rahul 19
3 Pooja 20
4 Aarti 19
This complete table is referred to as “Student Entity Set” and each row
represents an “entity”.
Representation as ER Diagram
1|Page
Here,
• Roll_no is a primary key that can identify each entity uniquely. • Thus, by
using student’s roll number, a student can be identified uniquely.
2|Page
Symbols Used
Example
In this ER diagram,
• Two strong entity sets “Student” and “Course” are related to each other. •
Student ID and Student name are the attributes of entity set “Student”. Student
ID is the primary key using which any student can be identified uniquely.
• Course ID and Course name are the attributes of entity set “Course”. Course
ID is the primary key using which any course can be identified uniquely.
• Double line between Student and relationship set signifies total participation.
It suggests that each student must be enrolled in at least one course.
• Single line between Course and relationship set signifies partial participation.
It suggests that there might exist some courses for which no enrolments are
made.
3|Page
2. Weak Entity Set
• A weak entity set is an entity set that does not contain sufficient attributes
to uniquely identify its entities.
• In other words, a primary key does not exist for a weak entity set. •
In this ER diagram,
• One strong entity set “Building” and one weak entity set “Apartment” are
related to each other.
• Strong entity set “Building” has building number as its primary key. • Door
number is the discriminator of the weak entity set “Apartment”. This is
because door number alone cannot identify an apartment uniquely as there
may be several other buildings having the same door number.
4|Page
• Double line between Apartment and relationship set signifies total
participation. It suggests that each apartment must be present in at least
one building.
• Single line between Building and relationship set signifies partial
participation. It suggests that there might exist some buildings which has
no apartment.
NOTE
• The combination of discriminator and primary key of the strong entity set
makes it possible to uniquely identify all entities of the weak entity set.
• Thus, this combination serves as a primary key for the weak entity set. •
Clearly, this primary key is not formed by the weak entity set completely.
Thus,
Primary key of Apartment
= Primary key of Building + Its own discriminator
= Building number + Door number
A single rectangle is used for the A double rectangle is used for the
representation of a strong entity representation of a weak entity set.
set.
5|Page
It contains sufficient attributes to It does not contain sufficient attributes to
form its primary key. form its primary key.
A diamond symbol is used for the A double diamond symbol is used for the
representation of the relationship that representation of the identifying
exists between the two strong entity relationship that exists between the strong
sets. and weak entity set.
A single line is used for the A double line is used for the representation
representation of the connection of the connection between the weak entity
between the strong entity set and the set and the relationship set.
relationship.
Total participation may or may not Total participation always exists in the
exist in the relationship. identifying relationship.
Important Note
6|Page
Attributes in ER Diagram
In ER diagram,
• Attributes are associated with an entity set.
• Attributes describe the properties of entities in the entity set. • Based on the
values of certain attributes, an entity can be identified uniquely which is
called primary key.
• There exists a specific domain or set of values for each attribute from
where the attribute can take its values.
Types of Attributes
1. Simple Attributes
Simple attributes are those attributes which cannot be divided further.
Example
Here, all the attributes are simple attributes as they cannot be divided further.
7|Page
2. Composite Attributes
Composite attributes are those attributes which are composed of many other
simple attributes.
Example
Here, the attributes “Name” and “Address” are composite attributes as they
are composed of many other simple attributes.
Single valued attributes are those attributes which can take only one value for a
given entity from an entity set.
Example
Here, all the attributes are single valued attributes as they can take only one
specific value for each entity.
8|Page
4. Multi Valued Attributes
Multi valued attributes are those attributes which can take more than one value
for a given entity from an entity set.
Example
Here, the attributes “Mob_no” and “Email_id” are multi valued attributes as
they can take more than one values for a given entity.
5. Derived Attributes
Derived attributes are those attributes which can be derived from other
attribute(s).
Example
Here, the attribute “Age” is a derived attribute as it can be derived from the
attribute “DOB”.
9|Page
6. Key Attributes
Key attributes are those attributes which can identify an entity uniquely in an
entity set.
Example
Here, the attribute “Roll_no” is a key attribute as it can identify any student
uniquely.
Relationship in ER Diagram
A relationship is defined as an association among several entities.
Example
‘Enrolled in’ is a relationship that exists between entities Student and Course.
Relationship Set
Example
10 | P a g e
Degree of a Relationship Set
The number of entity sets that participate in a relationship set is termed as the
degree of that relationship set. Thus,
Unary relationship set is a relationship set where only one entity set participates
in a relationship set.
Example
Binary relationship set is a relationship set where two entity sets participate in a
relationship set.
11 | P a g e
Example
Example
Cardinality in ER Diagram
Cardinality Constraint
12 | P a g e
Types of Cardinality Ratios
1. Many-to-Many Cardinality
Symbol Used
Example
Consider the following ER diagram.
Here,
• One student can enrol in any number (zero or more) of courses.
Symbol Used
Example
Consider the following ER diagram.
Here,
• One student can enrol in at most one course.
14 | P a g e
3. One-to-Many Cardinality
Symbol Used
Example
Consider the following ER diagram.
Here,
• One student can enroll in any number (zero or more) of courses.
Symbol Used
Example
Consider the following ER diagram.
Here,
• One student can enrol in at most one course.
16 | P a g e
Participation Constraints in DBMS
Participation constraints define the least number of relationship instances in
which an entity must compulsorily participate.
• Total participation
• Partial participation
1. Total Participation
• It specifies that each entity in the entity set must compulsorily participate
Example
Here,
• Double line between the entity set “Student” and relationship set “Enrolled
in” signifies total participation.
• It specifies that each student must be enrolled in at least one course.
17 | P a g e
2. Partial Participation
• It specifies that each entity in the entity set may or may not participate in
the relationship instance in that relationship set.
• That is why, it is also called as optional participation.
• Partial participation is represented using a single line between the entity set
and relationship set.
Example
Here,
• Single line between the entity set “Course” and relationship set “Enrolled in”
signifies partial participation.
• It specifies that there might exist some courses for which no enrolments
are made.
18 | P a g e
Steps to Create an ER Diagram
Let’s study the steps with an ER Diagram Example.
• Course
• Professor
19 | P a g e
Step 4: Identify Attributes
• You need to study the files, forms, reports, data currently maintained by
the organization to identify attributes. You can also conduct interviews
with various stakeholders to identify attributes.
• Initially, it’s important to identify the attributes without mapping them to
a particular entity.
• Once, you have a list of Attributes, you need to map them to the identified
entities.
• Ensure an attribute is to be paired with exactly one entity. If you think an
attribute should belong to more than one entity, use a modifier to make
it unique.
• Once the mapping is done, identify the primary Keys. If a unique key is
not readily available, create one.
Entity Primary Key Attribute
Student Student_ID StudentName
Professor Employee_ID ProfessorName
Course Course_ID CourseName
For Course Entity, attributes could be Duration, Credits, Assignments, etc. For the
sake of ease, we have considered just one attribute.
20 | P a g e
Best Practices for Developing Effective ER Diagrams
Here are some best practice or example for Developing Effective ER Diagrams.
These are:
• Eliminate any redundant entities or relationships.
• You need to make sure that all your entities and relationships are properly
labelled.
• There may be various valid approaches to an ER diagram. You need to make
sure that the ER diagram supports all the data you need to store. • You
should assure that each entity only appears a single time in the ER diagram.
• Name every relationship, entity, and attribute are represented on your
diagram.
• Never connect relationships to each other.
Example ER Model
21 | P a g e
Enhanced ER Model
Using the ER model for bigger data creates a lot of complexity while designing a
database model, So, in order to minimize the complexity Generalization,
Specialization, and Aggregation were introduced in the ER model and these were
used for data abstraction in which an abstraction mechanism is used to hide details
of a set of objects. Some of the terms were added to the Enhanced ER Model, where
some new concepts were added. These new concepts are:
22 | P a g e
• Generalization
• Specialization
• Aggregation
Generalization
Example
Specialization
23 | P a g e
Example
Specialization
Aggregation
Example
24 | P a g e
• Using aggregation, WORKS_FOR relationship with its entities
EMPLOYEE and PROJECT is aggregated into a single entity and
relationship REQUIRE is created between the aggregated entity and
MACHINERY.
Following rules are used for converting an ER diagram into the tables.
• A strong entity set with only simple attributes will require only one table in
relational model.
• Attributes of the table will be the attributes of the entity set. • The
primary key of the table will be the key attribute of the entity set.
25 | P a g e
Example
Roll_no Name
• A strong entity set with any number of composite attributes will require only
one table in relational model.
• While conversion, simple attributes of the composite attributes are taken
into account and not the composite attribute itself.
Example
26 | P a g e
Roll_no First_name Last_name House_no Street City
• A strong entity set with any number of multi valued attributes will require
two tables in relational model.
• One table will contain all the simple attributes with the primary key. •
Other table will contain the primary key and all the multi valued
attributes.
Example
Roll_no City
Roll_no Mobile_no
27 | P a g e
Rule-04: Translating Relationship Set into a Table
Example
NOTE
28 | P a g e
Rule-05: For Binary Relationships with Cardinality Ratios
The following four cases are possible.
• R (a1, b1)
• B (b1, b2)
NOTE: Here, combined table will be drawn for the entity set B and relationship
set R.
29 | P a g e
Case-03: For Binary Relationship with Cardinality Ratio m:1
• B (b1, b2)
NOTE: Here, combined table will be drawn for the entity set A and relationship
set R.
Here, two tables will be required. Either combine ‘R’ with ‘A’ or ‘B’.
Way-01
• AR (a1, a2, b1)
• B (b1, b2)
Way-02
• A (a1, a2)
30 | P a g e
Thumb Rules to Remember
While determining the minimum number of tables required for binary relationships
with given cardinality ratios, following thumb rules must be kept in mind.
• For binary relationship with cardinality ration m:n, separate and
individual tables will be drawn for each entity set and relationship. • For
binary relationship with cardinality ratio either m:1 or 1:n, always
remember “many side will consume the relationship” i.e. a combined
table will be drawn for many side entity set and relationship set. • For
binary relationship with cardinality ratio 1:1, two tables will be required. You
can combine the relationship set with any one of the entity sets.
Because cardinality ratio = 1:n, so we will combine the entity set B and
relationship set R. Then, two tables will be required:
• A (a1, a2)
31 | P a g e
Case-02: For Binary Relationship with Cardinality Constraint and Total
Participation Constraint from Both Sides
If there is a key constraint from both the sides of an entity set with total
participation, then that binary relationship is represented using only single table.
32 | P a g e
Practice Problems Based on Converting Er Diagram to Tables
Problem-01
Find the minimum number of tables required for the following ER diagram in
relational model.
Solution
• MR1 (M1, M2, M3, P1) [Rule 06, Case 01 – Total Participation] • P
(P1, P2)
• NR2 (P1, N1, N2) [Rule 07, Weak Entity with Total Participation]
Problem-02
Find the minimum number of tables required to represent the given ER diagram
in relational model.
33 | P a g e
Solution
Here,
• The Relationship with Entity A, Entity B, and Relationship R1 is m:1.
Entity A is in the Many (m) side and Entity B is in the One (1) side. • The
Relationship with Entity A, Entity C, and Relationship R2 is m:1. Entity A
is in the Many (m) side and Entity C is in the One (1) side. • The
Relationship with Entity B, Entity C, and Relationship R3 is m:n.
• AR1R2 (a1, a2, b1, c1) [Rule 05, Case 03 – m:1 (Many Side)] • B
(b1, b2) [Rule 05, Case 03 – m:1 (One Side)]
• C (c1, c2) [Rule 05, Case 01 – m:n (One Side)]
Problem-03
Find the minimum number of tables required to represent the given ER diagram
in relational model.
34 | P a g e
Solution
• A (a1, a2)
• R2 (a1, c1)
• D (d1, d2)
Problem-04
Find the minimum number of tables required to represent the given ER diagram
in relational model.
Solution
Here,
• The Relationship with Entity E1, Entity E2, and Relationship R1 is 1:n.
Entity E1 is in the One (1) side and Entity E2 is in the Many (n) side. • The
Relationship with Entity E3, Entity E2, and Relationship R2 is m:1. Entity
E2 is in the Many (m) side and Entity E3 is in the One (1) side.
• E1 (a1, a2)
• E3 (c1, c2)
35 | P a g e
Problem-05
Find the minimum number of tables required to represent the given ER diagram
in relational model.
Solution
Applying the rules that we have learnt; minimum 6 tables will be required:
• Loan (L_no, Amt, b_name) [Rule 06, Case 01 – Total Participation with 1:n
relationship (Many Side)]
• Borrower (C_name, L_no) [m:n Relationship]
36 | P a g e