You are on page 1of 51

Module 10: Entity

Relationship Diagram

1
TOPIC CONTENT

▪ Define ER Diagram
▪ ERD Notations
▪ Why use entity relationship diagrams
▪ Components of ER Diagram
▫ Entity
▫ Attributes
▫ Relationships
▪ Steps in creating ER Diagram
▪ Sample ERD
2
ENTITY-RELATIONSHIP DIAGRAM (ERD)
▪ The ERD represents the conceptual database as viewed
by the end user.
▪ It is a type of flowchart that illustrates how “entities”
such as people, objects or concepts relate to each
other within a system.
▪ An ERD uses data modeling techniques that can help
define business processes and serve as the foundation
for a relational database.
ENTITY-RELATIONSHIP DIAGRAM (ERD)
▪ ERDs main components: entities, attributes, and relationships.
▫ Entity represents a real-world object, the words entity and object are
often used interchangeably.
▪ Also known as ERDs or ER Models
▪ Symbols:
ENTITY-RELATIONSHIP DIAGRAM (ERD)
ENTITY-RELATIONSHIP DIAGRAM (ERD)
ERD Notations
▪ The Chen notation favors conceptual modeling.
▫ Developed by computer scientist Peter Chen, Chen ERD notation is considered to be a more
detailed method of illustrating entities and their relationships. It is widely used in database and
software design. Chen ERD notation primarily constitutes entities, attributes, relationships, and
cardinality.
▪ The Crow’s Foot notation favors a more implementation-oriented
approach.
▫ A crow's foot represents "many" or "infinite" These symbols are used in pairs to represent the
four types of cardinality that an entity may have in a relationship. The inner element of the
notation represents the minimum, and the outer element (closest to the entity) represents the
maximum.
▪ The UML notation can be used for both conceptual and implementation
modeling.
▫ A UML diagram is a diagram based on the UML (Unified Modeling Language) with the purpose of
visually representing a system along with its main actors, roles, actions, artifacts or classes, in
order to better understand, alter, maintain, or document information about the system.
ENTITY-RELATIONSHIP DIAGRAM (ERD)

Chen Notation Crow Foot’s Notation UML Notation


Why use relationship diagrams
▪ 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
▪ ER diagrams are translatable into relational tables which
allows you to build databases quickly
Why use relationship diagrams
▪ 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 ERP diagram
▪ ERD Diagram allows you to communicate with the logical
structure of the database to users
The components and features of an ER diagram
▪ ER Diagrams are composed of
▫ Entities
▫ relationships and
▫ Attributes

▫ They also depict cardinality, which defines


relationships in terms of numbers.
ENTITY
ENTITY
▪ A real-world thing either living or non- Examples of entities:
living that is easily recognizable and ▪ Person: Employee, Student, Patient
nonrecognizable. ▪ Place: Store, Building
▪ A definable thing—such as a person, ▪ Object: Machine, product, and Car
object, concept or event—that can have ▪ Event: Sale, Registration, Renewal
data stored about it. Think of entities as ▪ Concept: Account, Course
nouns.
▪ Examples: a customer, student, car or
product.
▪ The characteristics of entities are must
have an attribute, and a unique key. Every
entity is made up of some ‘attributes’
which represent that entity.
ENTITY CATEGORY
▪ Entity categories:
▫ Entities are categorized as strong, weak or associative.
▫ A strong entity can be defined solely by its own attributes, while
a weak entity cannot. An associative entity associates entities (or
elements) within an entity set.

STRONG ENTITY WEAK ENTITY


Strong Entity
▪ A strong entity is an entity type whose existence doesn't depend on any
other entity. Strong entity types have a key attribute. The key attribute
helps in identifying each entity uniquely.
WEAK ENTITY
Week Entity
▪ A weak entity is a type of entity which doesn’t have its key attribute. It
can be identified uniquely by considering the primary key of another
entity. For that, weak entity sets need to have participation.
Comparison
Comparison
Comparison
ATTRIBUTE
▪ A property or characteristic of an entity.
Attribute
▪ An attribute describes the property of an entity.
▪ Types of attributes:
▫ Simple attributes
▫ Key attributes
▫ Composite attribute
▫ Multivalued attribute
▫ Derived attribute
TYPES OF ATTRIBUTES
▪ Simple attributes are those
Student
drawn from the atomic value
domains; they are also
called single-valued
attributes. In the STUDENT Address
Roll No.
database, an example of this
would be: Name = {John} ;
Age = {23} Name Age
Key
TYPES OF ATTRIBUTES Attribute

▪ A key attribute can uniquely Student


identify an entity from an
entity set.
▪ For example, student roll
Address
number can uniquely identify Roll No.
a student from a set of
students.
Name Age
▪ text of key attribute is
underlined.
TYPES OF ATTRIBUTES
Composite attribute Student Postal
Code
▪ An attribute that is a
combination of other Municipality
Address
attributes is known as Roll No.

composite attribute.
Country
▪ For example, In student entity, Name Age
the student address is a
composite attribute as an
address is composed of other
attributes such as pin code,
state, country.
TYPES OF ATTRIBUTES
Multivalued attribute: Phone Postal
Student
No. Code
▪ An attribute that can hold
multiple values is known as Municipality
Address
multivalued attribute. It is Roll No.

represented with double


Country
ovals in an ER Diagram. Name Age
▪ For example – A person can
have more than one phone
numbers so the phone
number attribute is
multivalued.
TYPES OF ATTRIBUTES
Derived attribute: Phone Postal
Student
▪ A derived attribute is one whose No. Code
value is dynamic and derived from
another attribute. Address Municipality
Roll No.
▪ Attributed is calculated or otherwise
derived from another attribute, such Country
as age from a birthdate. Name Age
▪ For example – Person age is a
derived attribute as it changes over
time and can be derived from
another attribute (Date of birth).
RELATIONSHIP
▪ How entities act upon each other or are associated with each other.
▪ For example, the named student might register for a course. The two
entities would be the student and the course, and the relationship
depicted is the act of enrolling, connecting the two entities in that
way.
▪ symbol

Weak
Relationship
Relationship
CARDINALITY
▪ Defines the numerical attributes of the relationship between two entities or
entity sets.
▪ The three main cardinal relationships are one-to-one, one-to-many, and
many-many.
1. one-to-one example would be one student associated with one mailing
address.
2. one-to-many example (or many-to-one, depending on the relationship
direction). One student registers for multiple courses, but all those
courses have a single line back to that one student.
3. Many-to-many example: Students as a group are associated with
multiple faculty members, and faculty members in turn are associated
with multiple students.
CARDINALITY
▪ Cardinality
views: Cardinality can be
shown as look-across or
same-side, depending on
where the symbols are
shown.
▪ Cardinality
constraints: The minimum
or maximum numbers that
apply to a relationship
CARDINALITY
▪ One-to-one
▪ One entity from entity set X can be associated with at most one entity of
entity set Y and vice versa.
▪ Example: One student can register for numerous courses. However, all
those courses have a single line back to that one student.
CARDINALITY
One-to-many:
▪ One entity from entity set X can be associated with multiple entities of
entity set Y, but an entity from entity set Y can be associated with at
least one entity.
▪ For example, one class is consisting of multiple students.
CARDINALITY
Many to One
▪ More than one entity from entity set X can be associated with at most
one entity of entity set Y. However, an entity from entity set Y may or
may not be associated with more than one entity from entity set X.
▪ For example, many students belong to the same class.
CARDINALITY
Many to Many:
▪ One entity from X can be associated with more than one entity from Y
and vice versa.
▪ For example, Students as a group are associated with multiple faculty
members, and faculty members can be associated with multiple
students.
ENTITY KEYS (Attribute)
▪ Entity keys:
▫ Key are essential elements of
any relational tables
▫ It identify each tuple in a
relation uniquely
▫ A key is an attribute or set of
attributes which helps us in
uniquely identifying the rows
of a table.
▫ It also helps in establishing
relationship among tables.
ENTITY KEYS
▪ Entity keys can be super, candidate or primary.
▫ Super key: A set of attributes (one or more) that
together define an entity in an entity set.
▫ Candidate key: A minimal super key, meaning it has the
least possible number of attributes to still be a super key.
An entity set may have more than one candidate key.
▫ Primary key: A candidate key chosen by the database
designer to uniquely identify the entity set.
Properties of Primary Key
▪ A relation can only have one primary key
▪ Each value in a primary key must be unique
▪ Primary key cannot contain null values
ENTITY KEYS
ENTITY KEYS – Super Key
▪ Foreign Key of the entity
attribute in the entity
which is the primary key
of the related entity.
Foreign key helps to
establish the mapping
between two or more
entities.
Difference between Super Key and Candidate Key
▪ A single attribute or a set of attributes that
can uniquely identify all attributes of a
particular related is call super key. On the
other hand, a super key that is a proper
subset of another super key is called
candidate key.
▪ The set of super key is verified to find
candidate keys, whereas, the set of the
candidate keys is verified to select a single
primary key
For example, in a University
database, we might have
entities for Students,
Courses, and Lecturers.
Students entity can have
attributes like Rollno, Name,
and DeptID. They might
have relationships with
Courses and Lecturers.
Steps to Create an ERD

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
Steps to Create an ERD
Step 1) Entity Identification
We have three entities:
1. Student
2. Course
3. Professor
Steps to Create an ERD
Step 2) Relationship Identification
We have the following two relationships
1. The student is assigned a course
2. Professor delivers a course
Steps to Create an ERD
Step 3) Cardinality Identification
For the problem statement we know that,
• A student can be assigned multiple courses
• A Professor can deliver only one course
Steps to Create an ERD
Step 4) Identify Attributes
• You need to study the files, forms, reports, data currently maintained by
the organization to identify attributes. You can also conduct interviews
with various stakeholders to identify entities. Initially, it's important to
identify the attributes without mapping them to a particular entity.
• Once, you have a list of Attributes, you need to map them to the identified
entities. Ensure an attribute is to be paired with exactly one entity. If you
think an attribute should belong to more than one entity, use a modifier
to make it unique.
• Once the mapping is done, identify the primary Keys. If a unique key is not
readily available, create one.
Steps to Create an ERD

For Course Entity, attributes could be Duration, Credits, Assignments, etc. For the sake of ease we
have considered just one attribute.
Steps to Create an ERD

Step 5) Create the ERD


• A more modern representation of ERD Diagram
Best Practices 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
Sample ER Diagram
ER Diagram Notation Symbols
Sample ERD
• https://www.youtube.com/watch?v=I-XHfuJ43ic
• https://www.youtube.com/watch?v=W7fHUXQHE_I
• https://www.youtube.com/watch?v=z2hGlc-aDY0
• ERD
• https://www.gleek.io/blog/crows-foot-chen.html
• https://www.youtube.com/watch?v=8JFaaD1vzSY
Activity

•Create a simple library system using the


ERD by Chen and convert to Crow Foot
notation.
END

You might also like