Computing Magazine

Entity Relationship Model Tutorial

Posted on the 09 August 2019 by Badbones08 @fazii08

Entity relationship model

In this Entity relationship model based er diagram tutorial we will learn about important concepts of entity relationship diagram such as er diagram definition,er diagram symbols and notations,er diagram examples with solutions and different components of er diagram. What is Er Diagram ? What are different er diagram symbols? Give an er diagram examples with solutions. What are different components of er diagram?

What is entity relationship model?

Representation in DBMS to show relation between real world entities. This representation is  the Entity Relationship Model. This diagram basically shows the conceptual view of a database at any instance of time.  ER Model shows how different entities are related to each other in any system. Peter Chen introduced ER Model. He explained this model in his paper “The Entity Relationship Diagram” – Towards a Unified View of Data. ER Diagram are basically the diagrammatic representation of the DB Designs. So, they are mainly used to design the Relational Databases. Also, they are used during the planning stage of any Software Engineering Project. components of er diagram

Components of ER Diagram 

Some major components of ER diagram are as follows
  1. Entity: Any real world objects came under the category of entity. Entity can be any person, any object, any place or any event, relevant for a given database system.
For Example : A Pharmacy Management system can have the entities such as drugs, cash, injections, bills etc. There is a kind of entity which totally depends on the existence of other entity & that is known as the Weak Entity. Entities are represented using Rectangles.
  1. Attribute They are the properties through which an entity is defined. Suppose there is an entity called Student, then Student’s name, Student’s age, Student’s email address, Student’s phone number came under the category of attribute of the entity “Student”
There are following kind of attributes:
  • Simple attribute: Attribute whose values are already atomic & cannot be divided further.For Example The first name & last name of an entity “Student”.
  • Composite attribute : Attributes which are made up of more than one simple attributes. For Example The attribute ‘Name’ which contains First Name, Middle name and last name etc.
  • Single valued attribute: These attributes contain only single values. For Example The attribute “Age” of an entity “Student”
  • Multi valued attribute: These attributes contain multiple values. T is represented by double oval.For Example ‘Phone Number’ of an entity “Student”
  • Derived attribute: The attributes which are derived from other attributes & are not present in the database system are known to be called as Derived Attributes. For example The ‘Age’ of the entity ‘Student’ can be derived from the attribute “Date of Birth”. So age is the derived attribute. Derived attribute is represented by dotted oval.
3.Relationship : Relationship represents the association among the entities of an ER diagram. It is represented by diamond symbol.

ER Diagram Notations and Symbols

Different er diagram notations and symbols are shown in following figure

er diagram symbols             

Relationships between entities

If there are more than one entity in a DBMS, then there is a high chance that all the entities are related to each other, through some kind of relationships.These relationships are represented using a Diamond Shaped Box and as usual, entities are represented using Rectangular Box. All the entities in a relationship are connected using a hard line. When two entities are connected to each other, then it is known as Binary Relationship and the number of instance of any entity which can be associated with any other relation is known as Cardinality of the Entity. Relationships are basically the association between the entities.There are basically 4 types of cardinality of a relationship:
  1. ONE TO ONE
An entity in an entity set A can be associated with at-most one entity in other entity set B or an entity in set B can be associated with at most one entity in set A one to one cardinality

Example : One student can enroll in at-most one course or one course can be enrolled by at most one student.                                         

  1. ONE TO MANY
When an instance or entity  of an entity set A is associated with any number(zero or many) entities in other entity set B or an entity in entity set B is associated with at-most one entity in entity set A. then it is known as one to many to one relationship. Mainly ‘Many’ or ‘N’ should be in the right side of the relationship.
one to many cardinalilty in er diagram

Example: One student can enroll in any number of course ( including zero) or one course can be enrolled by at most one student.

  1. MANY TO ONE
When an entity or  instance of an entity set A is associated  with at most one entity in other entity set B or an entity in entity set B can be associated with any number of entities of entity set A then it is known as one to many relationship. Mainly ‘Many’ or ‘N’ should be in the left side of the relationship.
Entity relationship model tutorial

Example : One student can enrolled in at most one course or one course can be enrolled by any( zero or many) students.

  1. MANY TO MANY
When an entity in an entity set A is associated with any number of entities in an entity set B and vice versa then this type of cardinality or mapping is known as many to many. Mainly ‘Many’ or ‘N’ should be in the both side of the relationship.
many to many cardinality in er diagram

Example: One student can enroll in any number of course ( zero or many ) or one course can be enrolled by any( zero or many ) number of students.

ER Diagram Example with solution

An ER diagram for Customer and Loan entity is as shown in following figure.

Relationship between customer and loan entity set is borrower. It means customer borrow the loan. Different attributes of customer and loan entity are also shown.

Customer_id is the key attribute of Customer entity similarly loan_id is the key attribute of loan entity. 

Entity relationship model tutorial

ER Diagram Keys

In ER Modelling, Keys are used for indexing. Through keys, one can easily access any row without wasting much time and efficiency. It is very usable in the tables which millions of data or rows. Lets take an example of a table “EMPLOYEE” with the fields “EMP_ID, EMP_F_NAME, EMP_L_NAME, EMP_PHNO, EMP_EMAIL”. Basically there are 4 type of keys which plays the major role in ER Modelling, which are as follows:
  1. Primary key: It is that column of a table which has all the unique values inside it. Through primary key, the data in the table will be identified uniquely.
Ex. In a table “EMPLOYEE”, the “EMP_ID” (EmployeeID) which is assigned to every Employee uniquely, is known to be the primary key of the table.
  1. Composite key
When two or more attributes are combined together to form a primary key column or to identify any table data uniquely, this is composite key. Ex. In a table “EMPLOYEE”, the “EMP_PHNO”& “EMP_EMAIL” attributes, if combined together, form a type of primary key which is assigned to every Employee uniquely, is known to be the composite key of the table.

Participation constraints in ER Diagram

There are two types of participation constraints and these are as follows

Total Participation 

In total participation each entity is involved in the relationship. Total participation is represented by double lines in ER diagram. Total participation specifies that each entity in the entity set must compulsorily participate in at least one relationship instance the relationship set.

Total participation sometime also known as mandatory participants. Total Participation Example –In the following figure Double line between the entity set “Student” and relationship set “Enrolled in” signifies total participation.
participants constraints

Partial participation 

In this types of participation not all entities are involved in the relationship. Partial participation is represented by single line. It specifies that each entity in the entity set may or may not participate in the relationship instance in that relationship set.

That is why, it is sometime also known as optional participation
Partial Participation Example

partial participation constraints
Here in this example Single line between the entity set “Course” and relationship set “Enrolled in” represents partial participation.It specifies that there might exist some courses for which no enrollments are made.

Also Read : Blockchain’s Battle with Financial Inclusion — Part 1


Back to Featured Articles on Logo Paperblog