ER Diagram Representation

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Lecture Notes-4

ER Diagram Representation

Entity Relationship Diagram (ER Diagram) in DBMS:


An Entity–relationship model (ER model) describes the structure of a database with the help of a
diagram, which is known as Entity Relationship Diagram (ER Diagram). An ER model is a
design or blueprint of a database that can later be implemented as a database. ER diagrams are
created based on three basic concepts: entities, attributes and relationships.

An ER diagram shows the relationship among entity sets. An entity set is a group of similar
entities and these entities can have attributes. In terms of DBMS, an entity is a table or attribute
of a table in database. ER diagram shows the complete logical structure of a database.

For example, suppose we design a university database. In this database, the student will be an
entity with attributes like name, id, age, address, etc. The address can be another entity with
attributes like city, street name, pin code, etc and there will be a relationship between them.

Components of the ER Diagram


This model is based on three basic components:
 Entities
 Attributes
 Relationships

Figure: Components of ER Diagram

4/ ER Diagram Representation
1. Entity:
An entity is a thing in a real-world with independent existence. An entity can exist independently
and is distinguishable from other objects. It can be identified uniquely. 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.

i. Weak Entity:
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. For example –
a bank account cannot be uniquely identified without knowing the bank to which the account
belongs, so bank account is a weak entity.

2. Attribute
The attribute is used to describe the properties or characteristics of an entity. Oval or ellipse
shape is used to represent an attribute. For example, id, age, contact number, name, etc. can be
attributes of a student.

There are four types of attributes:


i. Key attribute
ii. Composite attribute
iii. Multivalued attribute
iv. Derived attribute

i. Key Attribute:
An attribute which can uniquely identify an entity in an entity set is called 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.

4/ ER Diagram Representation
ii. Composite Attribute:
An attribute that composed of many other attributes (combination of other attributes) is known as
a composite attribute. The composite attribute is represented by an ellipse, and those ellipses are
connected with an ellipse.

iii. 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 and email address.

iv. 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.

4/ ER Diagram Representation
3. Relationship
A relationship is used to describe the relation between entities. Diamond or rhombus is used to
represent the relationship.

There are four types of relationships:


i. One to One
ii. One to Many
iii. Many to One
iv. Many to Many

i. 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 person has only one passport and a passport is given to one
person.

ii. One-to-many relationship:


When only one instance of the entity on the left, and more than one instance of an entity on the
right associates with the relationship then this is known as a one-to-many relationship.
For example, Scientist can invent many inventions, but the invention is done by the only specific
scientist.

iii. 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 – many students can study in a single college but a student cannot study in many
colleges at the same time.

iv. 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-to-many relationship.
For example, Employee can assign by many projects and project can have many employees.

4/ ER Diagram Representation
Participation Constraints:
 Total Participation – It specifies that each entity in the entity set must compulsorily
participate in at least one relationship instance in that relationship set. That is why; it is
also called as mandatory participation. Total participation is represented using a double
line between the entity set and relationship set.
Example: Double line between the entity set “Student” and relationship set “Enrolled in”
signifies total participation. It specifies that each student must be enrolled in at least one
course.

 Partial participation − It specifies that each entity in the entity set may or may not
participate in the relationship. That is why; it is also called as optional participation.
Partial participation is represented using a single line between the entity set and
relationship set.
Example: “Courses” and “Enrolled_in” a relationship signifies the partial participation,
which means some courses are not enrolled by any of the student, i.e enrollments are
optional in that case.

Steps to Create an E-R Diagram (ERD):


Following are the steps to create an E-R Diagram.
Step 1) Entity Identification
Step 2) Relationship Identification
Step 3) Identify Attributes
Step 4) Create the E-R Diagram

Example:
In a university, a Student enrolls in Courses. A student must be assigned to at least one or more
Courses. Each course is taught by a single Professor. To maintain instruction quality, a
Professor can deliver only one course.

Solution:
Step 1) Entity Identification
We have three entities: (1) Student, (2) Course, (3) Professor

Step 2) Relationship Identification


We have the following two relationships
(1) The student is assigned a course, (2) Professor delivers a course

4/ ER Diagram Representation
Step 3) Identify Attributes
We have three entities Student, Course and Teacher.
Attributes of Entity Student are: Student_ ID, Student _Name & Student_Grade
Attributes of Entity Course are: Course_ ID, Course _Name
Attributes of Entity Professor are: Professor _ ID, Professor _Name & Professor_Salary

Step 4) Create the E-R Diagram

Figure: E-R diagram representation

Example:
Construct an E-R diagram for a College with a set of Students. Where the relationship between
Student and College is many to one and College is the entity set is total participation in StudyIn
relationship set.

Solution:

Figure: E-R diagram for college where, each College must have at-least one associated Student.

4/ ER Diagram Representation
Example:
Construct an E-R 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:

Figure: E-R diagram for a Car-insurance company

Example:
Design an E-R diagram for keeping track of the exploits of your favorite sports team. You should
store the matches played, the scores in each match, the players in each match and individual
player statistics for each match. Summary statistics should be modeled as derived attributes.

Solution:

Figure: E-R diagram for favorite team statistics.

4/ ER Diagram Representation
Example:
Construct an E-R diagram for a hospital with a set of patients and a set of medical doctors.
Associate with each patient a log of the various tests and examinations conducted.

Solution:

Figure: E-R diagram for a hospital.

Best Practices for Developing Effective ER Diagrams:

Here are some best practices or example for Developing Effective ER Diagrams.

 Eliminate any redundant entities or relationships.


 You need to make sure that all your entities and relationships are properly labeled.
 There may be various valid approaches to an ER diagram. You need to make sure that the
ER diagram supports all the data you need to store.
 You should assure that each entity only appears a single time in the ER diagram.
 Name every relationship, entity, and attribute are represented on your diagram.
 Never connect relationships to each other.
 You should use colors to highlight important portions of the ER diagram.

Why use ER Diagrams?

Here, are prime reasons for using the ER Diagram:

 Helps you to define terms related to entity relationship modeling.


 Provide a preview of how all your tables should connect, what fields are going to be on
each table.
 Helps to describe entities, attributes, relationships.

4/ ER Diagram Representation
 ER diagrams are translatable into relational tables which allow you to build databases
quickly.
 ER diagrams can be used by database designers as a blueprint for implementing data in
specific software applications.
 The database designer gains a better understanding of the information to be contained in
the database with the help of ER diagram.
 ER diagram allows you to communicate with the logical structure of the database to
users.

Difference between Strong and Weak Entity:

Strong Entity Weak Entity

A strong entity is an entity that is independent A weak entity is an entity set that cannot be
of any other entity in a schema. uniquely identified by its attributes alone.
Strong entity set always has a primary key. It does not have enough attributes to build a
primary key.
It contains a Primary key represented by the It contains a Partial Key which is represented
underline symbol. by a dashed underline symbol.
Strong entity is not dependent of any other Weak entity is dependent on strong entity.
entity.
The member of a strong entity set is called The member of a weak entity set called as a
as dominant entity set. subordinate entity set.
Strong entity is represented by single rectangle. Weak entity is represented by double rectangle.
Two strong entity’s relationship is represented While the relation between one strong and one
by single diamond. weak entity is represented by double diamond.
Strong entity may or may not participate in Weak entity always participates in entity
entity relationships. relationships.

4/ ER Diagram Representation

You might also like