ER model
o ER model stands for an Entity-Relationship model. It is a high-level data model. This
model is used to define the data elements and relationship for a specified system.
o It develops a conceptual design for the database. It also develops a very simple and easy to
design view of data. o In ER modeling, the database structure is portrayed as a diagram
called an entity-relationship diagram.
For example, Suppose we design a school database. In this database, the student will be an entity
with attributes like address, name, id, age, etc. The address can be another entity with attributes
like city, street name, pin code, etc and there will be a relationship between them.
Component of ER Diagram
1. Entity:
An entity may be any object, class, person or place. In the ER diagram, an entity can be represented
as rectangles.
Consider an organization as an example- manager, product, employee, department etc. can be taken
as an entity.
a. Weak Entity
Skip Ad
An entity that depends on another entity called a weak entity. The weak entity doesn't contain any
key attribute of its own. The weak entity is represented by a double rectangle.
2. Attribute
The attribute is used to describe the property of an entity. Eclipse is used to represent an attribute.
For example, id, age, contact number, name, etc. can be attributes of a student.
a. Key Attribute
The key attribute is used to represent the main characteristics of an entity. It represents a primary
key. The key attribute is represented by an ellipse with the text underlined.
b. Composite Attribute
An attribute that composed of many other attributes is known as a composite attribute. The
composite attribute is represented by an ellipse, and those ellipses are connected with an ellipse.
c. Multivalued Attribute
An attribute can have more than one value. These attributes are known as a multivalued attribute.
The double oval is used to represent multivalued attribute.
For example, a student can have more than one phone number.
d. Derived Attribute
An attribute that can be derived from other attribute is known as a derived attribute. It can be
represented by a dashed ellipse.
For example, A person's age changes over time and can be derived from another attribute like Date
of birth.
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.
Types of relationship are as follows:
a. One-to-One Relationship
When only one instance of an entity is associated with the relationship, then it is known as one to
one relationship.
For example, A female can marry to one male, and a male can marry to one female.
c. Many-to-one relationship
When more than one instance of the entity on the left, and only one instance of an entity on the
right associates with the relationship then it is known as a many-to-one relationship.
For example, Student enrolls for only one course, but a course can have many students.
d. Many-to-many relationship
When more than one instance of the entity on the left, and more than one instance of an entity on
the right associates with the relationship then it is known as a many-tomany relationship.
For example, Employee can assign by many projects and project can have many employees.
Rectangle: Represents Entity sets.
Ellipses: Attributes
Diamonds: Relationship Set
Lines: They link attributes to Entity Sets and Entity sets to Relationship Set
Double Ellipses: Multivalued Attributes
Dashed Ellipses: Derived Attributes
Double Rectangles: Weak Entity Sets
Double Lines: Total participation of an entity in a relationship set
Mapping Constraints
o A mapping constraint is a data constraint that expresses the number of entities to which
another entity can be related via a relationship set. o It is most useful in describing the
relationship sets that involve more than two entity sets. o For binary relationship set R on an
entity set A and B, there are four possible mapping cardinalities. These are as follows:
1. One to one (1:1)
2. One to many (1:M)
3. Many to one (M:1)
4. Many to many (M:M)
One-to-one
In one-to-one mapping, an entity in E1 is associated with at most one entity in E2, and an entity in E2
is associated with at most one entity in E1.
One-to-many
In one-to-many mapping, an entity in E1 is associated with any number of entities in E2, and an entity
in E2 is associated with at most one entity in E1.
Many-to-one
In one-to-many mapping, an entity in E1 is associated with at most one entity in E2, and an entity in
E2 is associated with any number of entities in E1.
Many-to-many
In many-to-many mapping, an entity in E1 is associated with any number of entities in E2, and an
entity in E2 is associated with any number of entities in E1.
Skip Ad
Types of Cardinality Ratios-
There are 4 types of cardinality ratios-
1. Many-to-Many cardinality (m:n)
2. Many-to-One cardinality (m:1)
3. One-to-Many cardinality (1:n)
4. One-to-One cardinality (1:1 )
Cardinality Constraint-
Before you go through this article, make sure that you have gone through the previous article on
Introduction to ER Diagrams.
1. Many-to-Many Cardinality-
By this cardinality constraint,
An entity in set A can be associated with any number (zero or more) of entities in set B. An
entity in set B can be associated with any number (zero or more) of entities in set A.
Symbol Used-
Example-
Consider the following ER diagram-
Here,
• One student can enroll in any number (zero or more) of courses.
• One course can be enrolled by any number (zero or more) of students.
2. Many-to-One Cardinality-
By this cardinality constraint,
• An entity in set A can be associated with at most one entity in set B.
• An entity in set B can be associated with any number (zero or more) of entities in set A.
Symbol Used-
Example-
Consider the following ER diagram-
Here,
One student can enroll in at most one course.
One course can be enrolled by any number (zero or more) of students.
3. One-to-Many Cardinality-
By this cardinality constraint,
An entity in set A can be associated with any number (zero or more) of entities in set B.
An entity in set B can be associated with at most one entity in set A.
Example-
Consider the following ER diagram-
Here,
• One student can enroll in any number (zero or more) of courses.
• One course can be enrolled by at most one student.
4. One-to-One Cardinality-
By this cardinality constraint,
An entity in set A can be associated with at most one entity in set B.
An entity in set B can be associated with at most one entity in set A.
Symbol Used-
Example-
Consider the following ER diagram-
Here,
• One student can enroll in at most one course.
• One course can be enrolled by at most one student.
Advantages And Disadvantages Of ER Model In
DBMS
ER model is a logical representation of an enterprise data. ER model is a diagrammatic representation of logical
structure of database.
ER model describes relationship among entities and attributes.
ER diagram is firstly developed by Peter Chen in 1976.
Advantages of ER Model
Conceptually it is very simple: ER model is very simple because if we know relationship between entities and
attributes, then we can easily draw an ER diagram.
Better visual representation: ER model is a diagrammatic representation of any logical structure of database. By
seeing ER diagram, we can easily understand relationship among entities and relationship.
Effective communication tool: It is an effective communication tool for database designer.
Highly integrated with relational model: ER model can be easily converted into relational model by simply
converting ER model into tables.
Easy conversion to any data model: ER model can be easily converted into another data model like hierarchical
data model, network data model and so on.
Disadvantages of ER Model
Limited constraints and specification
Loss of information content: Some information be lost or hidden in ER model Limited relationship representation:
ER model represents limited relationship as compared to another data models like relational model etc.
No representation of data manipulation: It is difficult to show data manipulation in ER model.
Popular for high level design: ER model is very popular for designing high level design
EER Model(Enhanced ER (EER) model)
EER is a high-level data model that incorporates the extensions to the original ER model.
It is a diagrammatic technique for displaying the following concepts
• Sub Class and Super Class
• Specialization and Generalization
• Aggregation
These concepts are used when the comes in EER schema and the resulting schema diagrams called as
EER Diagrams.
Features of EER Model
• EER creates a design more accurate to database schemas.
• It reflects the data properties and constraints more precisely.
• It includes all modeling concepts of the ER model.
• Diagrammatic technique helps for displaying the EER schema.
• It includes the concept of specialization and generalization.
• It is used to represent a collection of objects that is union of objects of different of different entity
types.
A. Sub Class and Super Class
• Sub class and Super class relationship leads the concept of Inheritance.
• The relationship between sub class and super class is denoted with symbol.
1. Super Class
• Super class is an entity type that has a relationship with one or more subtypes.
• An entity cannot exist in database merely by being member of any super class. For example: Shape
super class is having sub groups as Square, Circle,
Triangle.
2. Sub Class
• Sub class is a group of entities with unique attributes.
• Sub class inherits properties and attributes from its super class.
For example: Square, Circle, Triangle are the sub class of Shape super class.
B. Specialization and Generalization
DBMS Generalization
Generalization is a process in which the common attributes of more than one entities
form a new entity. This newly formed entity is called generalized entity.
Generalization Example
Lets say we have two entities Student and Teacher.
Attributes of Entity Student are: Name, Address & Grade
Attributes of Entity Teacher are: Name, Address & Salary
These two entities have two common attributes: Name and Address, we can make
a generalized entity with these common attributes. Lets have a look at the ER
model after generalization.
The ER diagram after generalization:
We have created a new generalized entity Person and this entity has the common
attributes of both the entities. As you can see in the following ER diagram that
after the generalization process the entities Student and Teacher only has the
specialized attributes Grade and Salary respectively and their common attributes
(Name & Address) are now associated with a new entity Person which is in the
relationship with both the entities (Student & Teacher).
Note:
1. Generalization uses bottom-up approach where two or more lower level entities
combine together to form a higher level new entity.
2. The new generalized entity can further combine together with lower level entity
to create a further higher level generalized entity.
2. Specialization
Specialization is a process in which an entity is divided into sub-entities. You can
think of it as a reverse process of generalization, in generalization two entities
combine together to form a new higher level entity. Specialization is a top-down
process.
The idea behind Specialization is to find the subsets of entities that have few
distinguish attributes. For example – Consider an entity employee which can be
further classified as sub-entities Technician, Engineer & Accountant because these
sub entities have some distinguish attributes.
In the above diagram, we can see that we have a higher level entity
“Employee” which we have divided in sub entities “Technician”, “Engineer” &
“Accountant”. All of these are just an employee of a company, however their role
is completely different and they have few different attributes. Just for the example,
I have shown that Technician handles service requests, Engineer works on a
project and Accountant handles the credit & debit details. All of these three
employee types have few attributes common such as name & salary which we had
left associated with the parent entity “Employee” as shown in the above diagram.
C. 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.
In real world, we know that a manager not only manages the employee working under them but he
has to manage the project as well. In such scenario if entity “Manager” makes a “manages”
relationship with either “Employee” or “Project” entity alone then it will not make any sense
because he has to manage both. In these cases the relationship of two entities acts as one entity. In
our example, the relationship “Works-On” between “Employee” & “Project” acts as one entity that
has a relationship “Manages” with the entity “Manager”.
Participation Constraints
• Total Participation − Each entity is involved in the relationship. Total participation is
represented by double lines.
• Partial participation − Not all entities are involved in the relationship. Partial participation
is represented by single lines.