Professional Documents
Culture Documents
Chapter at a Glance
Introduction to ER Model
Entity
Entity Type
Entity Instance
Entity Set
Attribute and its Type
Composite Attribute
Atomic Attribute
Derived Attribute
Stored Attribute
Relationship
Degree of Relationship
o Unary Relationship
o Binary Relationship
o Ternary Relationship
Cardinality of Relationship
o One to One
o One to Many
o Many to One
o Many to Many
Concept of Key
Super Key
Candidate Key
Primary Key
Multiple Relationship
Attribute of a Relationship
Aggregation
Solved Assignments
Exercises
CHAPTER 2
Entity Relationship Model (ER Model)
Introduction
Entity-relationship modeling is a high-level data modeling technique that helps
designers to create appropriate, accurate and useful conceptual models. E-R
models are best expressed using E-R diagrams (a graphical representation). In
the year of 1976 Professor Peter Chen has invented this technique to serve it as
a tool for useful communication between database designers and database
users. It is recognized the problems that are caused when developers and users
fail to understand each other. It is typical for developers and users to think that
they each know exactly what the other is thinking. Otherwise it leads
misunderstanding; sometimes developers build information systems that do not
meet user needs. The result is the failure of the system that was developed.
2.1.1 Entity
Definition: An entity is an object that exists in real world with independent
existence having certain properties and distinguishable from other objects.
For example, Samir Das is a student of BCA stream. We can say he is an entity
because he has certain properties like name, roll, year, class by which he is
distinguishable from other students. Similarly Dipak Sharma, an account holder
in Axis Bank is an entity because he has a name, a/c number, a/c opening date
by which he is distinguishable from other account holders.
Authored By: Prof. Soumik Das
For example, student is an entity type and account holder is another entity type.
If Samir Das and Dipak Sharma both are BCA students then they will be having
some common properties.
For example, if Samir Das is an account holder in Axis Bank and a BCA student
as well then he becomes an entity instance of student and account holder entity
type.
For example, all account holders of Axis Bank conforms an entity set. In the
same way we can say all the BCA student is an entity set.
2.1.5 Attributes
Definition: Entities are having certain properties by which they exist
independently in the real world called attributes.
Single-valued Attribute:
Multi-valued Attribute:
If more than one value is possible for a given attribute, we can say that is
a multi valued attribute.
For example, favorite food, languages known may have more than one
value.
For example, roll number, account number are the atomic attributes
because they can not be divided any further.
Composite Attribute:
Derived Attribute:
Stored Attribute:
An attribute from where the derived attributes are derived. For example,
age is derived from DOB, so DOB is the stored attribute.
2.1.6 Relationships
While entity types describe independent artifacts, relationship types describe
meaningful associations between entity types. To be very precise, the
relationship type describes that entities of entity types participating in the
relationship can build a meaningful association. The actual occurrence of the
association between entities is called a relationship. It is important to understand
that although we defined a relationship type, this does not mean that every pair
of entities builds a relationship. A relationship type defines only that relationships
can occur.
For example teacher entity type is associated with student entity type with
teaches relation in such a way teacher teaches student. So we can say these
two entity type teacher and student builds a meaningful association with the
relation teaches. On the other hand student entity type associated with
examination entity type with sit for relation in a way student sit for examination.
But teacher entity type is not associated with examination, because if they
associated no meaningful association will be made.
The number of entity sets that participate in a relationship is called the degree of
relationship. The three most common degrees of a relationship in a database are
unary (degree 1), binary (degree 2), and ternary (degree 3). We will briefly define
Authored By: Prof. Soumik Das
Unary Relationship:
Binary Relationship:
Ternary Relationship:
3.7
2.1.6.2 Cardinality of Relationships:
One-to-One Relationship:
In a one-to-one relationship, at most one instance of entity B can be
associated with a given instance of entity A and vice versa.
Figure 2.1
One-to-Many Relationship:
In a one-to-many relationship, many instances of entity B can be
associated with a given instance of entity A. However, only one instance
of entity A can be associated with a given instance of entity B. For
example, while a customer of a company can make many orders, an order
can only be related to a single customer.
Many-to-One Relationship:
In a many-to-one relationship, one instance of entity B can be associated
with a given instance of entity A. However, many instances of entity A can
be associated with a given instance of entity B.
Authored By: Prof. Soumik Das
Many-to-Many Relationship:
In a many-to-many relationship, many instances of entity A can be
associated with a given instance of entity B, and, likewise, many instances
of entity B can be associated with a given instance of entity A. For
example, a machine may have different parts, while each individual part
may be used in different machines.
2.2 Keys
A key attribute is a single attribute or a combination of attributes that uniquely
identify an individual instance of an entity type. No two instances within an entity
set can have the same key attribute value. For the STUDENT entity roll is the key
attribute since each student roll number is unique. Name, by contrast, cannot be
an identifier because two students can have the same name.
Super Key:
For example for the entity set student roll and name is a super key. The
name alone is not a super key because two students can have the same
name. Note that an entity set can have more than one super key.
Candidate Key:
Primary Key:
2.3 ER Diagram
ER diagram is a toll that represents the database in a graphical, symbolic and
easy to understand manner. It standardizes the concept of ER modeling and also
very useful for mapping the ER model to relational DBMS implementation. There
are some accepted standard to prepare an ER diagram for the conceptual design
phase of database. Actually ER diagrams enable designers and users to express
their understanding of what the planned database is intended to do and how it
might work, and to communicate about the database through a common
language.
Figure 2.2
CASE STUDY I
Let us assume a situation where BCA and MCA students are attending classes
of many subjects. So if we want to represent this fact with an ER diagram, we
need to go through the following phases
First of all we need to identify the entity set for the given case. Here we
can identify two entity sets STUDENT and SUBJECT.
Name
DOB
Roll
Phone
No
Subject
Name
Age
LEARNING
STUDENT
Stream
Street
Name
Address
SUBJECT
SubjectCode
Year
City
House
No
Figure 2.3
PIN
Recursive Relationship:
When the participating entity sets are not distinct in the relationship types,
they are referred recursive relationships. Figure 2.4 shows an example of
recursive relationship.
EMPLOYEE
N
1
Manager
Subordinate
MANAGES
Figure 2.4
Recursive Relationship
Participation Constraints:
MemberOf
N
STUDENTS
TEAM
1
LeaderOf
Figure 2.5
One-to-One:
PRINCIPAL
HAS
PLAYER
WORKSON
PROJECT
TEACHES
STUDENT
Many-to- One:
ENGINEER
COLLEGE
One-to-Many:
TEAM
MANAGES
Many-to- Many:
TEACHER
Unary Relationship:
PERSON
IsMarriedTo
p1
p2
r1
p3
r2
p4
r3
p5
r4
p6
p7
p8
Figure 2.6(A)
PERSON
Figure 2.6(B)
IsMarriedTo
Binary Relationship:
MANAGER
DEPARTMENT
Manages
m1
d1
r1
m2
r2
d2
m3
r3
d3
m4
r4
d4
r5
m5
d5
Figure 2.7(A)
MANAGER
Figure 2.7(B)
MANAGES
DEPARTMENT
Ternary Relationship:
TEACHER
TEACHES
t1
COURSE
c1
r1
t2
c2
r2
s1
s2
s3
STUDENT
Figure 2.8(A)
Ternary Relationship
TEACHES
TEACHER
STUDENT
Figure 2.8(B)
COURSE
Salary
ENGINEER
WorksOn
ID
Name
Manages
EmpID
Figure 2.9
Name
PROJECT
Duration
Budget
Multiple Relationship
PERSON
IsMarriedTo
Figure 2.10
Attribute of Relationship
Date
Subclass:
A subclass of entity set is a set entities with all the attributes found in the base
entity set and with some other attribute may associated with it. The
relationships in which the base class is participating, the subclass will
definitely participate in those relationships, with addition to that subclass may
be associated with other relationships.
For example, BCA STUDENT will have the attributes of STUDENT entity set.
More over some other attributes may also be associated with it.
IS-A Relationship:
Name
DOB
Roll
Age
Subject
Name
LEARNING
STUDENT
IS-A
BCA
STUDENT
SUBJECT
IS-A
GroupID
MCA
STUDENT
Figure 2.11
SubjectCode
THEORITICAL
PRACTICAL
IS-A Relationship
In Figure 2.11 we can see, BCA STUDENT and MCA STUDENT entity sets are
the subclasses of entity set STUDENT. The entity set BCA STUDENT will have
all the attributes of STUDENT entity set such as Roll, Name, DOB and Age.
Similarly entity set MCA STUDENT will have all the attributes of STUDENT entity
set, with addition to that MCA STUDENT will have GroupID as its attribute. On
the other hand a subject can be either theoretical or practical so the entity set
SUBJECT will have two entity sets as its subclass THEORITICAL and
PRACTICAL. These two entity set will inherit all the attributes from its base class
like BCA STUDENT and MCA STUDENT. This phenomenon is known as
attribute inheritance.
Authored By: Prof. Soumik Das
Specialization:
Note that, we can have more than one specialization from a given entity set. This
is known as multiple specialization. For example, entity set STUDENT can be
specialized with IS-A relationship as BCA STUDENT and MCA STUDENT. And
at the same time it can also be specialized as DAY SCHOLAR and
HOSTELLER. Figure 2.12 depicts multiple specialization.
Name
DOB
Roll
Age
STUDENT
IS-A
BCA
STUDENT
IS-A
GroupID
MCA
STUDENT
Figure 2.12
DAY SCHOLAR
Multiple Specialization
HOSTELLER
Name
DOB
Roll
Age
STUDENT
IS-A
BCA
STUDENT
IS-A
YEAR-I
Figure 2.13
YEAR-II
YEAR-III
Multilevel Specialization
Generalization:
IS-A relationship gives us the specialized entity sets from a given entity set. If
we approach in reverse direction of specialization, that means bottom-up
manner, we will get an entity set that is generalized form of specialized entity
sets. Figure 2.14 illustrates the generalization clearly.
Name
DOB
Roll
G
E
N
E
R
A
L
I
Z
A
T
I
O
N
Age
STUDENT
IS-A
BCA
STUDENT
Figure 2.14
S
P
E
C
I
A
L
I
Z
A
T
I
O
N
MCA
STUDENT
It is possible for a bank customer that he deposits money to his account as well
as he has taken a loan from the bank. So he is a borrower as well. Similarly a
subject may be an elective subject for BCA students at the same time it can be a
core subject for MCA students. But at the same time a student can not be a day
scholar and a hosteller.
Authored By: Prof. Soumik Das
Overlap Constraint:
SubjectCode
SUBJECT
O
IS-A
ELECTIVE
Figure 2.15
CORE
Overlap Constraint
Covering Constraint:
TOTAL
IS-A
IS-A
BCA
STUDENT
DAY SCHOLAR
Figure 2.16
HOSTELLER
Covering Constraint
The entities of subclass BCA STUDENT do not cover all the entities of base
class STUDENT. Because there exist many student entities those are not BCA
students. Thats why the covering is partial. On the other hand an entity of
STUDENT is either an entity of DAY SCHOLAR subclass or an entity of
HOSTELLER subclass. So collectively all the entities of these two subclasses
cover all the entities of base class STUDENT. Thats why here the covering is
total.
2.4.3 Aggregation
Definition: Aggregation - a feature of the entity relationship model that allows a
relationship set to participate in another relationship set.
ENGINEER
WORKS
ON
PROJECT
USES
COMPUTER
Figure 2.17
An Example
ENGINEER
WORKS
ON
USES
COMPUTER
Figure 2.18
Aggregation
PROJECT
SOLVED ASSIGNMENT
ASSIGNMENT I:
SOLUTION:
ASSIGNMENT II:
SOLUTION:
number,
year,
semester,
section
number,
ASSIGNMENT IV: Consider a database used to record the marks that students
get in different exams of different course offerings.
a. Construct an E-R diagram that models exams as
entities, and uses a ternary relationship, for the above
database.
**Note that, identifying the primary key of relations and imparting cardinality
ratios for all relations of the assignments are left for the students.
b.
Exercises
Instances
b.
Attributes
c.
Parameters
d.
None of these
Multi valued
b.
Stored
c.
Derived
d.
Composite
Unary relation
b.
Binary relation
c.
Ternary relation
d.
None of these
True
b.
False
5. When two entity sets are related with two atomic relations then it is
called
a.
Recursive relationship
b.
Multiple relationship
c.
Binary relationship
d.
All of these
Generalization
b.
Specialization
c.
Aggregation
d.
None of these
1.
2.
3.
4.
5.
1.
2.
3.
4.
5.
ii.
iii.
iv.