0% found this document useful (0 votes)
18 views42 pages

2 Chapter 2

The document provides an overview of Entity-Relationship (E-R) and Enhanced Entity-Relationship (EER) models used in database management systems, detailing their basic concepts, types of attributes, relationship sets, and mapping constraints. It explains the significance of keys, entity sets, and the process of converting E-R diagrams into tables, along with the advantages and limitations of the E-R model. Additionally, it introduces the EER model, which enhances the E-R model by incorporating advanced concepts such as specialization, generalization, and categorization.

Uploaded by

mahfuzfaisal29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views42 pages

2 Chapter 2

The document provides an overview of Entity-Relationship (E-R) and Enhanced Entity-Relationship (EER) models used in database management systems, detailing their basic concepts, types of attributes, relationship sets, and mapping constraints. It explains the significance of keys, entity sets, and the process of converting E-R diagrams into tables, along with the advantages and limitations of the E-R model. Additionally, it introduces the EER model, which enhances the E-R model by incorporating advanced concepts such as specialization, generalization, and categorization.

Uploaded by

mahfuzfaisal29
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

E-R and EER Models

Presented by
Dr. Md. Abir Hossain
Dept. of ICT
MBSTU
Reference Book: INTRODUCTION TO DATABASE MANAGEMENT SYSTEM
by Dr. Satinder Bal Gupta & Aditya Mittal
INDEX
i. Introduction
ii. Basic Concepts
iii. Types of Attribute
iv. Relationship Sets
v. Mapping Constrains
vi. Keys
vii. Entity – Relationship Diagram
viii. Types of Entity Sets
ix. Enhanced Entity-Relationship (EER) Model
x. Reduction of an E-R and EER Diagram into tables
Introduction
➢ Entity-Relationship model, is a high-level data model used in Database Management
Systems to represent the logical structure of database.
➢ It is conceptual design that simplifies the of data by defining entities, attributes, and
relationships between them.
Basic Concepts
▪ Enterprise: Enterprise refers to any kind of organization.
Ex. School, Colleges any company etc.

▪ Entity: Entity refers to an “object” or “thing” in real world. Object may be any person, place, event etc.
Ex. Students of colleges and schools, loans in banks, employees in any company etc.

▪ Attributes: These are the characteristics of any entity.


Ex. A student can be described by his name, age, address, height, class etc.

▪ Value: Value is the information or data which is stored in attributes of any entity.

▪ Entity Sets: All the entities having same attributes make an entity set.

▪ Domain: Domain or value set is the set of all values or information about any attribute.
Ex. Consider the student table shown in Figure 2.1. It describes the basic concepts.
Types of Attributes
1. Simple and Composite Attribute
i) Simple: Attributes are those which cannot be divided into subparts.
Ex. Age of a student.

ii) Composite: Attributes are those which can be divided into subparts.
Ex. Name of a student can be divided into First Name, Middle Name, and Last Name.

2. Single Valued and Multi-valued Attribute


i) Single Valued: An attribute having only single value for a particular entity is known as
single value attribute. Ex. Age of a student.
ii) Multi-valued: An attribute having more than one possible value for a particular entity is
known as multi-valued attribute.
Ex. Phone number of a student. A student may have more than one phone.
3. Derived Attributes and Stored Attributes
i) Derived Attributes : An attribute that can be derived from other known attributes is known
as derived attribute.
Ex. Age of employees can be derived if you know date of birth and system date.
Age = System date – Date of birth
ii) Stored Attributes : An attribute which cannot be derived by other known attributes is known
as stored attribute.
Ex. Date of birth of any employee.

*NULL Value : Null stands for nothing. An attribute have a null value if either the value of that attribute
is not known or the value is not applicable.

Caution: NULL is not equal to Zero (0). But you can say that NULL is blank as shown in Figure 2.2.
Relationship Sets
a) Relationship: A relationship is the association among several entities. It connects different
entities through a meaningful relation.
b) Relationship Set: A relationship set is a set of relationships of the same type.
➢ Ex. Employees work in different departments. Then relationship exists between employees and
departments because each employee must belongs to some department.
➢ Here, Employee and Department are two entity sets. r stands for relationship between Employee
and Department. Works_in is the relationship set as shown in Figure

• Descriptive Attributes : Attributes of any relationship set are known as descriptive attributes. Works_in
is a descriptive attribute.
Degree of Relationship Sets
Total number of entity sets participate in a relationship set is known as degree of that relationship set.
i) Binary Relationship Set: A relationship set in which only two entity sets are involved is
known as binary relationship set.
Ex.

ii) Ternary Relationship Set: A relationship set in which three entity sets are involved is known as
ternary relationship set or a relationship set having degree three.
Ex.
Role and Recursive Relationship Set
Total number of entity sets participate in a relationship set is known as degree of that relationship set.
▪ Role : The function of any entity which it plays in relationship set is called that entity’s role.
Ex. Employee plays the role of worker in his department in Figure 2.4.

▪ Recursive Relationship Set : When the same entity sets participate in same relationship set more
than once with different roles each time, then this type of recursive relationship set is known as
Recursive Relationship set.

For example, consider a relationship set works_in and two entity set student and college. A
student who attends weekend classes in college as student may also be lecturer in that college.
Then this person plays two roles (student, faculty) in same relationship set work_in.
Mapping Constrains
(5.a) Mapping Cardinalities (Cardinality Ratios):
It specifies the number of entities of an entity set that are associated with entities of another
entity set through a relationship set.
❑ Types of Mapping Cardinalities:
1. One to One (1 : 1) : An entity in X is associated with at most one entity in Y and an entity in Y
is associated with at most one entity in X.
Ex. A country has only one president. Any person may be the president of at most one
country

Figure: 1:1 relationship


2. One to Many (1 : N) : An entity in X is associated with any number of entities in Y. An entity in Y is
associated with at most one entity in X.
Ex. A manager has many employees under it but an employee works under only one manager

Figure: 1:N relationship


3. Many to One (N : 1) : An entity in X is associated with at most one entity in Y. An entity in Y is
associated with any number of entities in X.
Ex. A employee can work on single project while any project can be assigned to more than one employee.

Figure: N :1 relationship
4. Many to Many (M : N) : An entity in X is associated with any number (zero or more) of entities in Y and
vice versa.
Ex. A student can have more than one subject and one subject can be given to more than one student.

Figure: M: N relationship
Participation Constraints :
It tells the participation of entity set in relationship sets.
❑ There are two types of participations:
1. Partial participation : If only some entities from entity set E is participated in
relationships in set R then it is known as Partial participation.
Ex. Every customer may or may not take the loan , so Customer entity set is partially participated.

2. Total participation : If every entity from entity set E is participated with at least one
relation in relationship set R then it is known as Total participation.
Ex. Every loan is concerned with at least one customer of bank. So, loan entity set is totally
participated.
Keys
➢ A key is an attribute or set of attributes that is used to uniquely identify data in entity sets.
➢ The attributes which are used as key are known as key attributes. Rest of all are known as Non-key
attributes.
❑ Types of Keys:
1. Super Key : A super key is a set of collection of one or more than one attributes that can
identify data uniquely. Any entity set has more than one super key.
Ex.

In entity set Employee, shown in Figure (a), Super Keys are


(a) (ID, Name, Salary, Reg. No.)
(b) (ID, Name, Reg. No.)
(c) (ID) etc.
All combinations can identify data uniquely.
2. Candidate Key :
➢ The minimal super key is known as candidate key.
➢ Consider a super key and then take all of its proper subsets.
➢ If no one of the proper subsets are super key, then this super key is taken as candidate key.
Ex. ID and Reg. No. are candidate key.
3. Primary Key :
➢ An attribute which identifies data uniquely is known as Primary Key.
➢ The term Primary Key is used to denote Candidate key.
Ex. In entity set Employee, either Reg. No. is primary key or ID is primary key.
N.B. Any entity set can have more than one Candidate key but only one Primary Key.
4. Alternate Keys : All the candidate keys other than Primary Key are known as Alternate Keys.
Ex. If you take ID as Primary Key. Then, Reg. No. is an alternate key.
5. Secondary Key : An attribute or set of attributes which doesn’t identify data uniquely but identifies
a group of data is known as secondary key.
Ex. Name, Salary and Department No. are all secondary keys.

6. Foreign Key : A foreign key is an attribute in any entity set which is also a Primary Key in any other
entity set.
Ex. Dept-ID: This is an attribute in entity set Employee(a) and also a primary key in entity set Department(b).
Thus, it is a foreign key in Employee.
Entity Relationship Diagram(E-R Diagram) :
E-R diagrams represents the logical structure of a database. Symbols used in E-R diagrams are shown in Table 2.1.
Ex-1. An E-R diagram having two entity sets, Customer and Item.

Ex-2. An E-R diagram with entities Customer, Loan and Payment.


❑ Advantages and Limitation of E-R model

Advantages:
1. Straightforward relation representation: The relation representation of the database
model using E-R diagram are relatively more straightforward than other models.
2. Mapping with relational model: It can be easily mapped onto the relational model. The E-R
diagrams used in the E-R model can easily be transformed into relational tables. The entities and
attributes of E-R model can easily be transformed into relations (tables) and columns (fields) in a
relational model.
3. Communication tool: It is very simple and easy to understand with a minimum of training
efforts required. Therefore, the model can be used by the database designer to communicate the
design to the end user.
4. Design tool: E-R model can also be used as a design plan by the database developer to
implement a data model in specific database management software.
5. Easy conversion to other models: E-R diagrams can be easily converted to a network or
hierarchical data model.
6. Graphical representation: E-R model provides graphical and diagrammatical representation
of various entities, their attributes and relationships between entities.
7. Easy to modify: Modifications to E-R diagram at later stage is relatively easier than
in other models.

Limitation:
E-R model cannot express relationships between relationships. In other words, E-R model is not
capable to express relationship set between relationship sets.
This limitation can be overcome by using EER model.
Types of Entity Sets
There are two types of entity sets as given below:
a) Strong Entity Sets: Entity set having any key attributes are known as Strong Entity sets.
Ex. The Figure shows strong entity set Student having key attribute Reg_No.

b) Weak Entity Sets: Entity sets having no key attributes are known as Weak Entity sets.
Ex. The Figure below shows weak entity set Table having no key attributes to identify the tuples
uniquely.

N.B. A weak entity set is always associated with another entity set to make it meaningful.
This another entity set is known as Identifying entity set.
9. Enhanced Entity-Relationship (EER) Model
What is EER?
EER model is basically the enhanced version of E-R model which includes all the basic concepts of
E-R model with capability to support additional semantic concepts of complex applications.

❑ Concepts of EER
▪ Specialization
▪ Generalization
▪ Categorization

➢ Before discussing the concepts of specialization, generalization, and categorization two another
entity types superclass (supertype) and subclass (subtype) are need to be described.
1. Superclass Entity Type (Supertype) : A superclass entity type is a generic entity type that includes
one or more distinct subclasses that require to be represented in a data model.

2. Subclass Entity Type (Subtype) : A subclass entity type is a more specialized entity type that has a
distinct role in the organization. (A subclass is a member of superclass.)
Ex.
9.a) Specialization : Specialization is a process by which any existing entity set is divided into
smaller entity sets according to the distinct or different nature of entities.
9.b)Generalization: Generalization is a process by which two or more entity sets can be
combined into a single entity set by determining similarities between the entities.
Ex.

Here Employee and Customer are two entity sets. They have common feature that both are Person.
❑ Specialization and Generalization Constraints
The following constraints are applied on specialization and generalization to capture important
business rules of the relationships in an enterprise.

❖ There are Two types of constraints :


1. Participation Constraints: Discussed in (5.b)
2. Disjoint Constraints : According to Disjoint constraint if the subclasses of a specialization/
generalization are disjoint then an entity can be a member of only one subclass of that
specialization/generalization.
Ex.
Suppose any employee ‘Martin’ works as part time employee
for Bank then it can only belong to subclass ‘Part Time
Employee’.
9.c) Attribute Inheritance: Attribute Inheritance is a process by which lower-level entity set
inherits (or taken) some properties of its higher-level entity set.
Ex.

Here entity sets Employee and Customer inherits attributes Person_ID, Name, Address, Age from Person entity set.
9.d) Aggregation: Aggregation in DBMS is process of combining two or more entities to form a
more meaningful entity.

Ex.

In this example, the Employee and Branch alone do not make sense and are not useful. However,
when they are combined through the aggregation process, a more meaningful entity Manger is
formed. This New entity can perform better and provide more meaningful information.
9.e) Categorization: The subclass having more than one superclass is known as category and the
process of defining a category is known as Categorization.
Ex.

Categorization Symbol

In a bank, a person can be either an employee or a client and both of them may be investor. So, here Subclass
employee and client act as disjoint Superclasses and subclass investor acts as category.
10. Reduction of an E-R and EER Diagram into tables
To represent the database in tabular form, E-R diagrams have to be reduced in tables. For each
entity set, make different table and for each relationship set make a different table.

10.1 Reduction of Strong Entity Sets into Tables


For a strong entity set E with attributes a1, a2, ..., an,
➢ Step-01: Make a table having same name as of entity set E
➢ Step-02: Make n number of columns where ‘number of columns’ = ‘number of
attributes’ and columns name = entity set name.
Ex.
Consider a strong entity set Department with two attributes
Dept-ID and Dept-name. Then the corresponding table will be
10.2 Reduction of Composite Attributes
For a composite attribute, create a separate column for each component attribute or
parts of composite attributes.
Ex.
Consider the example shown in Figure 2.20. The Name is a composite attribute with three
component attributes First, Middle and Last. So, make three columns First-name, Middle-
name and Last-name. Then the corresponding table shown in Figure 2.22

Figure 2.20. E-R Diagram of entity set Employee


10.3 Reduction of Multi-valued Attributes
For multi-valued attributes, make a separate table with columns C1 which represent the primary key
of entity set or relationship set and with columns C2 which represent the multi-valued attributes.
Rows are equal to total number of values of that attribute.

Ex.
Consider Figure 2.20 in which Phone-No. is multi-valued attribute. So, make a table with two
columns, one is Emp-ID (primary key of Employee) and second is Phone-No. (multi-valued
attribute). Give any name to that table. The table is shown in Figure 2.22.
If any employee has two phone numbers, then it is possible to make two different entries in table and so on.

Figure 2.20. E-R Diagram of entity set Employee


10.4 Reduction of Weak Entity Sets
Let A be the weak entity set and B be the strong entity set on which A depends. Then, it is possible to
make a table with table name same as of Weak Entity Set having columns equal to the attributes of
Weak Entity set plus Primary Key of the Strong Entity set on which Weak Entity Set depends.

Ex.
Consider the E-R diagram shown in Figure 2.24, in which Payment is a Weak entity set that
depends upon Strong entity set Loan(has primary key). So, make a table with table name
Payment having four columns as shown in Figure 2.25.
10.5 Reduction of Relationship Sets
Let R be the relationship set and E1, E2, ..., EN be the entity sets participating in R. Make a table with
table name same as of Relationship Set having columns equal to number of attributes in relationship
set (descriptive attributes) and primary keys of all participating entity sets.
Ex.
Consider the ER diagram shown in Figure 2.20, having relationship set Works-in having two
participating entity sets, Employee and Department. The corresponding table is shown in Figure
2.26.

Figure 2.20. E-R Diagram


10.5.i) Redundant Tables
Redundant tables in DBMS refer to the situation where the same information is stored in multiple
tables, leading to unnecessary repetition and increased storage requirements. This can occur when
reducing aggregation into tables, particularly when dealing with relationship sets between weak and
strong entity sets.

10.5.ii) Combination of Tables


Combination of tables refers to the process of merging or joining two or more tables based on
common column or attribute. This is typically done to combine data from multiple tables into single
table for easier querying and analysis.
10.6 Reduction of Generalization
In generalizations, higher level entity sets and lower level entity sets are considered. Make a table for
higher level entity set with all its attributes. For lower level entity set, make a table with all its
attributes with primary key attributes of its higher level entity set.
Ex.
Consider E-R diagram shown in Figure 2.20, in which Employee is high level entity set and Full
Time Employee and Part Time Employee are two lower level entity sets. So, make three tables as
given below:
➢ Employee [Emp-ID, Dept-ID, First-Name, Middle-Name, Last-Name, Salary]
➢ Full Time Employee [Emp-ID, Qualification]
➢ Part Time Employee [Emp-ID, Hours-Worked]

Figure 2.20. E-R Diagram of entity set Employee


10.7 Reduction of Aggregation
Reduction of aggregation into tables is simple. Consider the E-R diagram shown in Figure 2.19. For all
entity sets, make tables as discussed earlier. For making tables for relationship sets, consider the
same approach as discussed earlier.
Ex.
Take an example of relationship set Manages. Make a table manages with all descriptive
attributes, primary key of entity set Manager and the relationship set works-on.
❑ Problem Exercise
❖ Problem 1:
Construct an E-R diagram for a hospital with a set of patients and a set of medical doctors. Associate with
each patient, a log of various tests and examinations conducted. Construct the appropriate tables for this E-R
diagram and list the tables with their attributes, primary key and foreign keys.

Solution: The E-R diagram is shown in Figure 2.28.


The Tables are as follows :
1. Patient (Pat-ID, name, address, admitted-date, check-out-date, room-no., bed-no., ward-no, doc-ID)
2. Ward (Ward-no., name, capacity)
3. Doctor (Doc-ID, name, fee, specialization)
4. Test (Test-ID, name, date, time, result, Pat-ID)
5. Primary key is shown by ______.
6. Foreign key is shown by _ _ _ _ _ _.
Thank You

You might also like