Entity-Relationship Model
The ER model defines the conceptual view of a
database. It works around real-world entities and the
associations among them.
ER model is considered a good option for designing
databases.
A database can be modeled as:
a collection of entities,
relationship among entities.
Entity Set
An entity is an object that is of interest and
distinguishable from other objects.
An entity can be a real-world object, either animate or
inanimate, that can be easily identifiable.
For example, in a school database, students, teachers, classes,
and courses offered can be considered as entities.
An entity set/entity type is a set of entities of the
same type that share the same properties.
An entity set is a collection of similar types of entities.
Example: set of all persons, companies, trees, teachers
Attributes
An entity is represented by a set of attributes, that is
descriptive properties possessed by all members of an
entity set.
Entities are represented by means of their properties,
called attributes. All attributes have values.
For example, a student entity may have name, class, and age
as attributes.
Types of Attributes
Simple attribute − Simple attributes are atomic values, which
cannot be divided further.
For example, a student's phone number is an atomic value of 10
digits.
Composite attribute − Composite attributes are made of more
than one simple attribute.
For example, a student's complete name may have first_name and
last_name.
Derived attribute − Derived attributes are the attributes that do
not exist in the physical database, but their values are derived
from other attributes present in the database.
For example, average_salary, age, etc.
Single-valued attribute − contain single value.
For example − Aadhar_No, roll_no.
Multi-valued attribute − may contain more than one values.
For example, a person can have more than one phone number, email_address,
etc.
Entity Sets and Attributes
customer_id customer_ customer_ customer_ loan_ amount
name street city number
Relationship
A relationship is an association among several
entities. A set of relationships of similar type is called a
relationship set.
Eg.: Employee occupies office, an employee works_at a
department, a student enrolls in a course. Here, occupies,
works_at and enrolls are called relationships.
Like entities, a relationship too can have attributes. For
instance, the depositor relationship set between entity
sets customer and account may have the attribute
access-date.
Relationship Set borrower
Relationship Set depositor
Degree of a Relationship Set
Refers to number of entity sets that participate in a
relationship set.
Relationship sets that involve two entity sets are
binary (or degree two). Generally, most relationship
sets in a database system are binary.
Relationship sets may involve more than two entity
sets. Ternary = degree 3 and so on.
Example: Suppose employees of a bank may have jobs
(responsibilities) at multiple branches, with different
jobs at different branches. Then there is a ternary
relationship set between entity sets employee, job,
and branch
Mapping Cardinality Constraints
Cardinality defines the number of entities in one entity
set, which can be associated with the number of
entities of other set via relationship set.
It expresses the number of entities to which another
entity can be associated via a relationship set.
Most useful in describing binary relationship sets.
For a binary relationship set the mapping cardinality
must be one of the following types:
One to one
One to many
Many to one
Many to many
Mapping Cardinalities
One-to-one − One entity from entity set A can be
associated with at most one entity of entity set B and
vice versa.
One-to-many − One entity from entity set A can be
associated with more than one entities of entity set B
however an entity from entity set B, can be associated
with at most one entity.
Many-to-one − More than one entities from entity set
A can be associated with at most one entity of entity
set B, however an entity from entity set B can be
associated with more than one entity from entity set A.
Many-to-many − More than one entities from entity
set A can be associated with more than one entities of
entity set B, and vice versa.
Mapping Cardinalities
One to one One to many
Mapping Cardinalities
Many to one Many to many
Keys
A super key of an entity set is a set of one or more
attributes whose values uniquely determine each entity
among entity set.
A candidate key of an entity set is a minimal super
key.
Although several candidate keys may exist, one of the
candidate keys is selected to be the primary key.
Example:
roll_number of a student
Customer_id of customer
account_number of account
ER Diagram
Entity: Entities are represented by means of
rectangles. Rectangles are named with the entity set
they represent.
Attributes: Attributes are represented by means of
ellipses. Every ellipse represents one attribute and is
directly connected to its entity (rectangle).
ER Diagram
Composite attributes are depicted by extending
ellipse further into simple attributes.
Multivalued attributes are depicted by double
ellipse.
Derived attributes are depicted by dashed ellipse.
ER Diagram With Attributes
ER Diagram
Diamonds represent relationship sets.
Lines link attributes to entity sets and entity sets to
relationship sets.
Underline indicates primary key attributes
Cardinality Constraints
We express cardinality constraints by drawing either a
directed line (), signifying “one,” or an undirected line
(—), signifying “many,” between the relationship set
and the entity set.
In the one-to-many relationship a loan is associated
with at most one customer via borrower, a customer is
associated with several (including 0) loans via borrower
In many-to-many relationship, a customer is associated
with several (possibly 0) loans via borrower and a loan
is associated with several (possibly 0) customers via
borrower
Cardinality Constraints
Participation of an Entity Set in a
Relationship Set
Total participation (indicated by double line): every
entity in the entity set participates in at least one
relationship in the relationship set
Eg.: participation of loan in borrower is total
Partial participation: some customer entities may not
participate in any relationship in the relationship set
Eg.: participation of customer in borrower is partial
ER Diagram with Ternary Relationship
Weak Entity Sets
An entity set that does not have a primary key is
referred to as a weak entity set.
The existence of a weak entity set depends on the
existence of a identifying entity set
It must relate to the identifying entity set via a total,
one-to-many relationship set from the identifying to
the weak entity set
It is depicted using a double diamond.
The discriminator (or partial key) of a weak entity set is
the set of attributes that distinguishes among all the
entities of a weak entity set.
The primary key of a weak entity set is formed by the
primary key of the strong entity set on which the weak
entity set is existence dependent, plus the weak entity
set’s discriminator.
Weak Entity Sets
A weak entity set is depicted by double rectangles.
We underline the discriminator of a weak entity set
with a dashed line like payment_number
Primary key for payment – (loan_number,
payment_number)
Extended ER Model
EER diagrams extend ER diagrams to represent the
additional subgroupings, called subclasses or subtypes
Example: EMPLOYEE may be further grouped into:
SECRETARY, ENGINEER, TECHNICIAN, …
Based on the EMPLOYEE’s Job
MANAGER
EMPLOYEEs who are managers
SALARIED_EMPLOYEE, HOURLY_EMPLOYEE
Based on the EMPLOYEE’s method of pay
Each is called a subclass of EMPLOYEE
EMPLOYEE is the superclass for each of these
subclasses
Extended ER Features: Generalization
A bottom-up design process – combine a number of
entity sets that share the same features into a higher-
level entity set.
The process of generalizing entities based on their
similar characteristics, where the common entity
contain the properties of all the generalized entities, is
called generalization.
For example, pigeon, house sparrow, crow and dove can all be
generalized as Birds.
Extended E-R Features: Specialization
Top-down design process; Specialization is the opposite
of generalization. In specialization, a group of entities
is divided into sub-groups based on their
characteristics.
These sub groupings become lower-level entity sets
that have attributes or participate in relationships that
do not apply to the higher-level entity set.
Take a group ‘Person’ for example. A person has name,
date of birth, gender, etc. These properties are
common in all persons, human beings. Similarly, in a
school database, persons can be specialized as teacher,
student, or a staff, based on what role they play in
school as entities.
Depicted by a triangle component labeled ISA. The ISA
relationship also referred to as superclass - subclass
relationship
Specialization Example
Design Constraints on
Specialization/Generalization
Constraint on whether or not entities may belong to
more than one lower-level entity set within a single
generalization.
Disjoint- an entity can belong to only one lower-level entity
set
Overlapping- an entity can belong to more than one lower-
level entity set
Completeness constraint - specifies whether or not
an entity in the higher-level entity set must belong to
at least one of the lower-level entity sets within a
generalization.
Total- an entity must belong to one of the lower-level entity
sets
Partial- an entity need not belong to one of the lower-level
entity sets
Extended E-R Features: Aggregation
Aggregation is a process in which a single entity alone is not able
to make sense in a relationship so the relationship of two entities
acts as one entity.
An ER diagram is not capable of representing relationship between
an entity and a relationship which may be required in some
scenarios. In those cases, a relationship with its corresponding
entities is aggregated into a higher level entity.
Extended E-R Features: Aggregation
For Example, Employee working for a project may require some
machinery. So, REQUIRE relationship is needed between
relationship WORKS_FOR and entity MACHINERY. Using
aggregation, WORKS_FOR relationship with its entities EMPLOYEE
and PROJECT is aggregated into single entity and relationship
REQUIRE is created between aggregated entity and MACHINERY.
Example: Company Database
Company is organized into DEPARTMENTs. Each
department has a name, number and an employee who
manages the department. We keep track of start date of
the department manager. A department may have several
locations.
Each department controls a number of PROJECTs. Each
project has a unique name, unique number and is located
at a single location.
We store each EMPLOYEE’s social security number,
address, salary, sex, and birthdate.
Each employee works for one department but may work on
several projects.
We keep track of the number of hours per week that an
employee currently works on each project.
We also keep track of the direct supervisor of each
employee.
Each employee may have a number of DEPENDENTs. For
each dependent, we keep track of their name, sex,
birthdate, and relationship to the employee.
Initial Design: Company Database
Refining: Company Database
Following 6 relationship types are identified with
degree 2:
WORKS_FOR (between EMPLOYEE, DEPARTMENT)
MANAGES (also between EMPLOYEE, DEPARTMENT)
CONTROLS (between DEPARTMENT, PROJECT)
WORKS_ON (between EMPLOYEE, PROJECT)
SUPERVISION (between EMPLOYEE (as subordinate),
EMPLOYEE (as supervisor))
DEPENDENTS_OF (between EMPLOYEE, DEPENDENT)
In the refined design, some attributes from the initial
entity types are refined into relationships:
Manager of DEPARTMENT -> MANAGES
Works_on of EMPLOYEE -> WORKS_ON
Department of EMPLOYEE -> WORKS_FOR
MANAGES and WORKS_FOR are distinct relationship
types between EMPLOYEE and DEPARTMENT
Recursive relationship type: SUPERVISION
Summary of notation for ER diagrams
Summary of notation for ER diagrams
ER Diagram
Benefits:
Simple
Visual representation
Ease of mapping to the relational model
Weakness:
No representation of data manipulation
Designing an ER Diagram
Design ER model for University database with following requirements
The university keeps track of each student's name, student
number, social security number, current address and phone
number, permanent address and phone number, birthdate, sex,
class, major department, minor department, degree program.
Both social security number and student number are unique for
each student. All students will have at least a major department.
Each department is described by a name, department code, office
number, office phone, and college. Both the name and code have
unique values for each department.
Each course has a course name, description, course number,
number of credits, level and offering department. The course
number is unique for each course.
Each section has an instructor, semester, year, course, and section
number. The section number distinguishes sections of the same
course that are taught during the same semester/year; its value is
an integer. A grade report must be generated for each student
that calculates his or her average GPA.
ER Diagram for Online Book Store
Degree DName DCode OfficeNumber
Name StudentID SSN
Major In
Birth date
OfficePhone
Department
Sex Student
College
Class Minor In
Address
City State Zip
Offer
CName
Grade_Report
CourseDesc
Letter Grade Instructor Year Course
CNumber
GPA
Credits
Numeric Grade Section Belong_To
SectionNumber Semester