2/25/2024 UCS310: Database Management Systems 1
E-R Model
2/25/2024 UCS310: Database Management Systems 2
Basic concept of E-R diagram
Basic concepts
• What is Database Design?
• Database Design is a collection of processes that facilitate the designing, development, implementation and
maintenance of enterprise database management systems.
• What is E-R diagram?
• E-R diagram: (Entity-Relationship diagram)
• The ER data model was developed to facilitate database design by allowing specification of an enterprise
schema that represents the overall logical structure of a database.
• The ER data model employs three basic concepts:
• entity sets,
• relationship sets,
• attributes.
• The ER model also has an associated diagrammatic representation, the ER diagram, which can express the
overall logical structure of a database graphically.
2/25/2024 UCS310: Database Management Systems 3
E-R diagram
Entity
• An entity is an object that exists and is distinguishable from other objects.
• An entity is a person, a place or an object.
• An entity is represented by a rectangle which contains the name of an entity.
• Entities of a college database are:
• Student
• Professor/Faculty
• Course
• Department
• Result
• Class
Exercise:
• Subject List the different entities of bank database.
List the different entities of hospital database.
2/25/2024 UCS310: Database Management Systems 4
Entity:
•Tangible Entity: Tangible Entities are those entities which exist in the
real world physically that can be touched, seen, or measured.
•Example: Person, car, buildings etc.
•Intangible Entity: Intangible Entities are those entities which exist only
logically and have no physical existence.
•Example: Bank Account, login information etc.
2/25/2024 UCS310: Database Management Systems 5
Entity Set
An entity set is a set of entities of the same type that share the same
properties.
Example:
All persons having an account in a bank
All the students studying in a college
All the professors working in a college
Set of all accounts in a bank
E-R diagram
Attributes
• Attribute is properties or details about an entity.
• An attribute is represented by an oval containing name of an attribute.
• Attributes of Student are:
• Roll No
• Student Name RollNo Name
• Branch
• Semester
• Address Student
• Mobile No
• Age
• SPI
• Backlogs Exercise Write down the different attributes of Faculty entity.
2/25/2024
Exercise Write down the different attributes of Account entity.
UCS310: Database Management Systems 7
E-R diagram
Relationship
• Relationship is an association (connection) between several entities.
• It should be placed between two entities and a line connecting it to an entity.
• A relationship is represented by a diamond containing relationship's name.
2/25/2024 UCS310: Database Management Systems 8
Degree of a Relationship
• A Relationship represents an association between two or more entities.
• Relationships are classified in terms of degree, connectivity, cardinality, and
existence.
• The degree of a relationship is the number of entities associated with the
relationship.
• The n-ary relationship is the general form for degree n.
• Special cases are the binary, and ternary, where the degree is 2, and 3,
respectively
• A recursive binary relationship occurs when an entity is related to itself.
• Example:
• "some employees are married to other employees".
• “Employee work_for a manager who is also an employee.
2/25/2024 UCS310: Database Management Systems 9
E-R diagram
E-R Diagram of a Library System
Primary Key Primary Key
Attributes
RollNo Name Relationship BookNo Name
Student Issue Book
Branch Sem Entities Author Price
2/25/2024 UCS310: Database Management Systems 10
E-R diagram
Ternary Relationship
ProjectID Project Name
Project
FacID Name RollNo Name
Faculty Guide Student
Branch Technology Branch Sem
2/25/2024 UCS310: Database Management Systems 11
E-R diagram
Types of Attributes
• Simple Attribute
• Cannot be divided into subparts
• E.g. RollNo, Age
• Composite Attribute
• Can be divided into subparts
• Name
• (first name, middle name, last name)
• Address
• (street, road, city)
2/25/2024 UCS310: Database Management Systems 12
E-R diagram
Types of Attributes
• Single-valued Attribute
• Has single value
• E.g. RollNo, Age
• Multi-valued Attribute
• Has multiple (more than one) value
• PhoneNo
• (person may have multiple phone nos)
• Email_ID
• (person may have multiple emails)
2/25/2024 UCS310: Database Management Systems 13
E-R diagram
Types of Attributes
• Stored Attribute
• It’s value is stored physically in the database
• E.g. Birthdate
• Derived Attribute
• It’s value is derived or calculated from other attributes
• Age
• (can be calculated using current date and birthdate)
2/25/2024 UCS310: Database Management Systems 14
E-R diagram
Types of Attributes
• Key Attribute:
• Key attributes are those attributes which can identify an entity uniquely in an entity set .
• Example: Roll_no.
• Descriptive Attribute: Attributes of the relationship is called descriptive attribute.
2/25/2024 UCS310: Database Management Systems 15
E-R diagram
Entity with all types of Attributes
2/25/2024 UCS310: Database Management Systems 16
Exercise
Draw an E-R diagram of following pair of entities
Customer & Account
Customer & Loan
Doctor & Patient
Student & Project
Student & Teacher
Note: Take four attributes per entity with one primary key attribute.
Keep proper relationship between two entities.
Mapping Cardinality (Cardinality Constraints)
It represents the number of entities of another entity set which are
connected to an entity using a relationship set.
It is 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
One-to-One relationship (1 – 1)
An entity in A is associated with only one entity in B and an entity in B is associated with
only one entity in A.
customer borrow loan
A1 B1
C1 L1
A2 B2
C2 L2
C3 L3
A B
Example: A customer is connected with only one loan using the relationship borrower and a
loan is connected with only one customer using borrower.
One-to-Many relationship (1 – N)
An entity in A is associated with more than one entities in B and an entity in B is associated
with only one entity in A.
customer borrow loan
A1 B1
C1 L1
A2 B2
C2 L2
C3 L3
A B
L4
Example: A loan is connected with only one customer using borrower and a customer is
connected with more than one loans using borrower.
One-to-Many relationship (1 – N)
Many-to-One relationship (N – 1)
An entity in A is associated with only one entity in B and an entity in B is associated with
more than one entities in A.
customer borrow loan
A1 B1
C1 L1
A2 B2
C2 L2
C3 L3
A B
C4
Example: A loan is connected with more than one customer using borrower and a customer
is connected with only one loan using borrower.
Many-to-One relationship (N – 1)
Many-to-Many relationship (N – N)
An entity in A is associated with more than one entities in B and an entity in B is associated
with more than one entities in A.
customer borrow loan
A1 B1
C1 L1
A2 B2
C2 L2
C3 L3
A B
C4 L4
Example: A customer is connected with more than one loan using borrower and a loan is
connected with more than one customer using borrower.
Many-to-Many relationship (N – N)
Mapping Cardinality (Cardinality Constraints) [Exercise]
Draw an E-R diagram and specify which type of mapping cardinality will be there in the
following examples:
Each customer has only one account in the bank and each account is held by only one
customer. [single account]
Each customer has only one account in the bank but an account can be held by more
than one customer. [joint account]
A customer may have more than one account in the bank but each account is held by
only one customer. [multiple accounts]
A customer may have more than one account in the bank and each account is held by
more than one customer. [join account as well as multiple accounts]
A student can work in more than one project and a project can be done by more than
one student.
A student can issue more than one book but a book is issued to only one student.
A subject is taught by more than one faculty and a faculty can teach more than one
subject.
Participation of an Entity Set in a Relationship set
Participation of an Entity Set in a Relationship set
Representation of Cardinality in ER
The cardinality of a relationship is the actual number of related occurrences for
each of the two entities.
E-R diagrams also provide a way to indicate cardinality of the relationship.
An edge between an entity set and a relationship set can have an associated
minimum and maximum cardinality, shown in the form l..h, where l is the
minimum and h the maximum cardinality.
A minimum value of 1 indicates total participation of the entity in the
relationship.
A maximum value of 1 indicates that the entity participates in at most one
relationship, while a maximum value * indicates no limit.
The label 1..* or 1..1 on an edge is equivalent to a double line.
Representation of Cardinality in ER
The edge between Loan and Cust_Loan has a cardinality constraint of 1..1, meaning the
minimum and the maximum cardinality are both 1.
That is, each loan must have exactly one associated customer.
The limit 0..* on the edge from Customer to Cust_Loan indicates that a customer can have
zero or more loans.
Thus, the relationship Cust_Loan is one to many from customer to loan, and further the
participation of loan in Cust_Loan is total.
Direction Symbol
The direction of a relationship indicates the
originating entity of a relationship.
The entity from which a relationship originates is
the parent entity; the entity where the relationship
terminates is the child entity.
The type of the relation is determined by the
direction of line connecting relationship component
and the entity.
To distinguish different types of relation, we draw
either a directed line or an undirected line between
the relationship set and the entity set.
Directed line is used to indicate one occurrence and
undirected line is used to indicate many
occurrences in a relation as shown in next case.
Direction Symbol
Weak Entity Set
The entity set which does not has sufficient attributes to form a primary key is called as weak
entity set. An entity set that has a primary key is called as Strong entity set.
Payment-date
loan-no amount payment-no Payment-amount
loan L_P payment
Strong Entity Weak Entity Weak Entity
Set Relationship Set
• Weak entity set is indicated by double rectangle.
• Weak entity relationship set is indicated by double
diamond.
Weak Entity Set
A member of a strong entity set is called dominant entity and member of weak
entity set is called as subordinate entity.
A weak entity set does not have a primary key but we need a means of
distinguishing among all those entries in the entity set that depend on one
particular strong entity set.
i.e. the existence of a weak entity set depends on the existence of a strong
entity set.
The primary key of a weak entity set is created by combining the primary key
of the strong entity set on which the weak entity set existence depends and
the weak entity set’s discriminator.
For example, payment_no is acts as discriminator for payment entity set. It is
also called as the Partial key of the entity set.
Superclass and Subclass
Super Class Sub Class
A superclass is an entity from which another A subclass is an entity that is derived from
entities can be derived. another entity.
E.g, E.g,
an entity account has two subsets saving_account and current_account entities
saving_account and current_account are derived from entity account.
So an account is superclass. So saving_account and current_account are
subclass.
Super Class
Account
Saving_Account Current_Account
Sub Class
Generalization
A generalization hierarchy is a form of abstraction that specifies that two or more entities
that share common attributes can be generalized into a higher-level entity type called a
super type or generic entity.
The lower level of entities becomes the subtype, or categories, to the super type. Subtypes
are dependent entities.
Generalization is used to emphasize the similarities among lower-level entity sets
and to hide differences.
It makes ER diagram simpler because shared attributes are not repeated.
Generalization is denoted through a triangle component labeled ‘IS_A”,
Bottom Up Approach.
Generalization
Specialization
Specialization is the process of taking subsets of a higher-level entity set to form lower level
entity sets.
It is a process of defining a set of subclasses of an entity type, which is called as super class
of the specialization.
The process of defining subclass is based on the basis of some distinguish characteristics of
the entities in the super class.
Top Down Approach
For example,
specialization of the Employee entity type may yield the set of subclasses namely
Salaried_Employee and Hourly_Employee on the method of pay
Specialization
Generalization and Specialization
Generalization Specialization
It extracts the common features of multiple entities to It splits an entity to form multiple new entities that
form a new entity. inherit some feature of the splitting entity.
Name Address Name Address
SPI Salary
Person Person
Name Name
ISA ISA
Top-down approach
Address Address
Bottom-up
approach
Student Faculty Student Faculty
SPI Salary SPI Salary
Generalization v/s Specialization
Generalization Specialization
The process of creation of group from various The process of creation of sub-groups within
entities is called generalization. an entity is called specialization.
It is Bottom-up approach. It is Top-down approach.
The process of taking the union of two or The process of taking a sub set of higher level
more lower level entity sets to produce a entity set to form a lower level entity set.
higher level entity set.
It starts from the number of entity sets and It starts from a single entity set and creates
creates high level entity set using some different low level entity sets using some
common features. different features.
Generalization & Specialization example
Name Address
PID City
Person
ISA
Salary Employee Customer Balance
ISA
Full Time Part Time
Days Hour
Worked Worked
Aggregation
One limitation of the E-R model is that it cannot
express relationships among relationships.
The best way to model a situation like this is by
the use of aggregation.
Thus, the relationship set work_on relating the
entity sets Employee, Branch and Job is a
higher-level entity set.
Such an entity set is treated in the same
manner, as is any other entity set.
We can then create a binary relationship
Manages between work_on and Manager to
represent who manages what tasks.
Aggregation: Example 2
▪ Consider the ternary relationship proj_guide, which we saw earlier
▪ Suppose we want to record evaluations of a student by a guide on a project
• Relationship sets eval_for and proj_guide
represent overlapping information
• Every eval_for relationship corresponds to a
proj_guide relationship
• However, some proj_guide relationships
may not correspond to any eval_for
relationships
• So we can’t discard the proj_guide
relationship
• Eliminate this redundancy via aggregation
• Treat relationship as an abstract entity
• Allows relationships between relationships
• Abstraction of relationship into new entity
2/25/2024 UCS310: Database Management Systems 44
Aggregation: Example 2
▪ Eliminate this redundancy via aggregation without introducing redundancy, the
following diagram represents:
• A student is guided by a particular instructor on a particular project
• A student, instructor, project combination may have an associated evaluation
Reduction to Relational Schemas
▪ To represent aggregation, create a schema containing
• Primary key of the aggregated relationship,
• The primary key of the associated entity set
• Any descriptive attributes
▪ In our example:
• The schema eval_for is:
eval_for (s_ID, project_id, i_ID, evaluation_id)
• The schema proj_guide is redundant.
2/25/2024 UCS310: Database Management Systems 45
E-R Notation
E-R diagram of Hospital Management System
MRID
PatID Name HosID Name
Medical Record Has Patient Admitted Hospital
Report Name ISA Trea Has
ts
Indoor Outdoor
Doctor
RoomNo
IPDID OPDID DrID Dr Name
Charge
Steps to design E-R diagram
1. Identify the Entities.
2. Find relationships among these entities.
3. Identify the key attributes for every Entity.
4. Identify other relevant attributes
5. Draw the complete e-r diagram with all attributes including the primary key
Question: Draw ER Diagram
Case Study 1
Consider, a university contains many departments. Each department can offer any number of
courses. Many teachers can work in a department. A teacher can work only in one department.
For each department there is a Head. A teacher can be head of only one department. Each
teacher can take any number of courses. A student can enroll for any number of courses. Each
course can have any number of students.
Step1: Identify the Entities as
Step 2: Relationship:
University,
• Department and course (1:M)
Department,
• Department & teacher(1:M)
Course,
• Department Head and teacher(1:1)
Teacher,
• Teacher and course(1:M)
Student
• Student & course(M:M)
Note: Consider University as single instance
Step 3: Key Attributes:
Step 4: Relevant Attributes:
D_no,
d_name,loc, c_name, credits, t_name, mob_no, name, address etc.
C_code,
Roll_no,
t_code
Case Study 1
Solution:
Case Study 2
Construct an ER diagram for a car insurance company whose customers own one or more
cars each. Each car has associated with it zero to any number of recorded accidents.
Solution:
2/25/2024 UCS310: Database Management Systems 53