100% found this document useful (1 vote)
163 views57 pages

Understanding Entity Relationship Models

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
163 views57 pages

Understanding Entity Relationship Models

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Entity Relationship-Model

KRISHNA PRIYA , CSE ,IIIT NUZVID


Introduction of ER Model

► Peter Chen developed the ER diagram in 1976 .


► The ER model was created to provide a simple and
understandable model for representing the structure and logic of
databases.
► It has since evolved into variations such as the Enhanced ER
Model and the Object Relationship Model.
► The Entity Relational Model is a model for identifying entities to
be represented in the database and representation of how
those entities are related.
► The ER data model specifies enterprise schema that represents
the overall logical structure of a database graphically.
Entity-Relationship Model

► An Entity-Relationship Model represents the


structure of the database with the help of a
diagram.
► ER Modelling is a systematic process to design a
database as it would require you to analyze all
data requirements before implementing your
database.
Why Use ER Diagrams In DBMS?

► ER diagrams are used to represent the E-R model in a database,


which makes them easy to convert into relations (tables).
► ER diagrams provide the purpose of real-world modeling of
objects which makes them intently useful.
► ER diagrams require no technical knowledge and no hardware
support.
► These diagrams are very easy to understand and easy to create
even for a naive user.
► It gives a standard solution for visualizing the data logically.
► It reduces complexity and allows database designers to build
databases quickly
Entity Relationship Diagram
► ER Model is used to model the logical view of the system from a data
perspective which consists of these symbols:
► An Entity Relationship Diagram is a diagram that represents
relationships among entities in a database.
► It is commonly known as an ER Diagram. An ER Diagram in DBMS
plays a crucial role in designing the database.
► Today’s business world previews all the requirements demanded by
the users in the form of an ER Diagram.
► Later, it's forwarded to the database administrators to design the
database.
Symbols Used in ER Model

► ER Model is used to model the logical view of the system from a data
perspective which consists of these symbols:
► Rectangles: Rectangles represent Entities in the ER Model.
► Ellipses: Ellipses represent Attributes in the ER Model.
► Diamond: Diamonds represent Relationships among Entities.
► Lines: Lines represent attributes to entities and entity sets with other
relationship types.
► Double Ellipse: Double Ellipses represent Multi-Valued Attributes.
► Double Rectangle: Double Rectangle represents a Weak Entity.
What is an ER Diagram?

► An Entity Relationship Diagram (ER Diagram) pictorially explains the


relationship between entities to be stored in a database.
► Fundamentally, the ER Diagram is a structural design of the
database. It acts as a framework created with specialized symbols
for the purpose of defining the relationship between the database
entities.
► ER diagram is created based on three principal components:
entities, attributes, and relationships.
Symbols Used in ER Diagrams
Example: E-R diagram

The following diagram showcases


two entities - Student and Course,
and their relationship.
The relationship described
between student and course is
many-to-many, as a course can
be opted by several students, and
a student can opt for more than
one course.
Student entity possesses attributes
- Stu_Id, Stu_Name & Stu_Age. The
course entity has attributes such
as Cou_ID & Cou_Name.
Components of ER Diagram

► You base an ER Diagram on three basic concepts:


► Entities
► Weak Entity
► Attributes
► Key Attribute
► Composite Attribute
► Multivalued Attribute
► Derived Attribute
► Relationships
► One-to-One Relationships
► One-to-Many Relationships
► Many-to-One Relationships
► Many-to-Many Relationships
Entities

► An entity can be either a living or non-living component.


► It showcases an entity as a rectangle in an ER diagram.
► For example, in a student study course, both the student and
the course are entities.
► An Entity may be an object with a physical existence – a
particular person,
► car, house, or
► employee – or it
► may be an object with
► a conceptual existence –
► a company, a job, or a university course.
Entity Set:

► Entity Set: An Entity is an object of Entity Type and a set of all entities is called
an entity set.
► For Example, E1 is an entity having Entity Type Student and the set of all
students is called Entity Set. In ER diagram, Entity Type is represented as:
► 1. Strong Entity
► A Strong Entity is a type of entity that has a key Attribute. Strong Entity does not
depend on other Entity in the Schema. It has a primary key, that helps in
identifying it uniquely, and it is represented by a rectangle. These are called
Strong Entity Types.
► 2. Weak Entity
► An Entity type has a key attribute that uniquely identifies each entity in the
entity set. But some entity type exists for which key attributes can’t be defined.
These are called Weak Entity types.
A weak entity

► A weak entity type is represented by a Double Rectangle. The participation of weak


entity types is always total.
► The relationship between the weak entity type and its identifying strong entity type is
called identifying relationship and it is represented by a double diamond.
► A weak entity depends on another entity to exist. It does not have a primary key but
a partial key, which helps identify its instances in combination with the identifying
entity’s primary key.
Example of Weak Entity
Attributes

► Attributes are the properties that define the entity


type. For example, Roll_No, Name, DOB, Age,
Address, and Mobile_No are the attributes that define
entity type Student. In ER diagram, the attribute is
represented by an oval.
Key Attribute

► The attribute which uniquely identifies each entity in the


entity set is called the key attribute.
► For example, Roll_No will be unique for each student. In
ER diagram, the key attribute is represented by an oval
with underlying lines.
Composite Attribute

► An attribute composed of
many other attributes is
called a composite attribute.
► For example, the Address
attribute of the student Entity
type consists of Street, City,
State, and Country.
► In ER diagram, the composite
attribute is represented by an
oval comprising of ovals.
Multivalued Attribute

► An attribute consisting of more than one value for a given entity.


► For example, Phone_No (can be more than one for a given
student).
► In ER diagram, a multivalued attribute is represented by a double
oval.
Derived Attribute

► An attribute that can be derived from other attributes of


the entity type is known as a derived attribute. e.g.; Age
(can be derived from DOB).
► In ER diagram, the derived attribute is represented by a
dashed oval.
The Complete Entity Type Student with
its Attributes can be represented as:
Relationship

► A Relationship is a logical link between two or more entities, depicting how the entities interact with
each other. Relationships help to define the associationns and dependencies between entities in a
database.
► There are four major types of relationships:
► 1. One to One Relationship
► In this type of relationship, a single instance of an entity A is associated with a single instance of entity
B. For instance, in a company database, an entity ‘Employee’ can have a one-to-one relationship
with an entity ‘EmployeeDetails’, where each employee has one set of details.
► 2. One to Many: This is a relationship where a single instance of an entity A can be associated with
multiple instances of entity B, but each instance of entity B can be associated with only one instance
of entity A. For example, a ‘Department’ entity can have a one-to-many relationship with an
‘Employee’ entity, representing that one department can have many employees, but each
employee belongs to one department.
► 3. Many to One: This is the inverse of the one-to-many relationship, where many instances of entity A
can be associated with a single instance of entity B.
► 4. Many to Many: In this relationship, many instances of entity A can be associated with many
instances of entity B. For example, an ‘Author’ entity can have a many-to-many relationship with a
‘Book’ entity, indicating that one author can write many books, and one book can have many
authors.
Relationship Type and Relationship Set

► A Relationship Type represents the association between entity types.


► For example, ‘Enrolled in’ is a relationship type that exists between entity type
Student and Course.
► In ER diagram, the relationship type is represented by a diamond and
connecting the entities with lines.
relationship set

► A set of relationships of the same type is known as a relationship set.


► The following relationship set depicts S1 as enrolled in C2, S2 as enrolled in C1,
and S3 as registered in C3.
Degree of a Relationship Set

► The number of different entity sets participating in a


relationship set is called the degree of a relationship
set.
► 1. Unary Relationship: When there is only ONE entity
set participating in a relation, the relationship is
called a unary relationship. For example, one person
is married to only one person.
► Binary Relationship: When there are TWO entities set
participating in a relationship, the relationship is
called a binary relationship. For example, a Student is
enrolled in a Course.
► Ternary Relationship: When there are n entities set
participating in a relation, the relationship is called
an n-ary relationship.
Binary Relationship:
► Binary Relationship: A binary relationship exists when exactly two entity type participates.
When such a relationship is present we say that the degree is 2.

► This is the most common degree of relationship. It is easy to deal with such relationship as
these can be easily converted into relational tables.
For example, we have two entity type ‘Customer’ and ‘Account’ where
each
‘Customer’ has an ‘Account’ which stores the account details of the
‘Customer’. Since
we have two entity types participating
we call it a binary relationship.
Also, one
‘Customer’ can have many
‘Account’ but each ‘Account’
should belong to only one
‘Customer’.
We can say that it is a one-to-many binary relationship.
Ternary Relationship:

► A ternary relationship exists when exactly three entity type participates. When such a
relationship is present we say that the degree is 3.
► As the number of entity increases in the relationship, it becomes complex to convert them
intorelational tables.

For example, we have three entity type ‘Employee’,


‘Department’ and ‘Location’.

relationship between these entities are defined as an


employee works in a department, an employee
works at a particular location. So, we can see we
have three entities participating in a relationship so it
is a ternary relationship. The degree of this relation
is 3
n-ary Relationship:

► An N-ary relationship exists when ‘n’ number of entities are participating.


So, any number of entities can participate in a relationship.
► There is no limitation to the maximum number of entities that can
participate.
Mapping Constrains

► For binary relationship set R on an entity set A


and B, there are four possible mapping
cardinalities.
► a. One-to-One (1:1)
► b. One-to-Many (1:M)
► c. Many-to-One (M:1)
► d. Many-to-Many (M:M)
One-to-One
Relationship

► When a single element of an entity is associated with a single element of another entity,
it is called 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 student has only one identification card and an identification card is
given to one person.

or example: A female can marry to one male,


and a male can marry to one female.
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.
One-Many to Relationship
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 amany-to-one relationship.
► For example, Student enrolls for only one course, but a course can have many students.
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
Many-to-Many Relationship
Participation Constraints

► The participation constraint specifies the number of


instances of an entity can participate in a relationship set
► Types of Participation Constraints
Total Participation

► The Participation of an entity set E in a relationship set R is said to be total


if every entity in E participates in at least one relationship in R.
► The participation of entity set A in the
relationship set is total because every entity of
A participates in the relationship set
► and

► The participation of entity set B in the


relationship set is also total because every
entity of B also participates in the relationship
Set
Partial Participation

► The participation of an entity set E in relationship set R is said to be partial if only


some entities in E participate in relationships in R.
► The participation of entity set A in the
relationship set is partial because only some
entities of A participate in the relationship set.
► while
► The participation of entity set B in the
relationship set is total because every entity of
B participates in the relationship se
The total participation Example

► In ERD, the total participation is denoted by doubled-line between


entity set and relationship set and partial participation is denoted
by single line between entity set and relationship set.
► That is why, it is also called as mandatory participation.
Example:

► Suppose an entity set Student related to an entity set Course through Enrolled relationship
set.
► The participation of entity set course in enrolled relationship set is partial because a course
may or may not have students enrolled in.
► It is possible that only some of the course entities are related to the student entity set
through the enrolled relationship set.
► The participation of entity set student in enrolled relationship set is total because every
student is expect to relate at least one course through the enrolled relationship set
partial participation

► Here,
► Single line between the entity set “Course” and relationship set “Enrolled in” signifies
partial participation.
► It specifies that there might exist some courses for which no enrollments are made.
Cardinality Constraints

► Here cardinality represents the number of times an entity of an entity set


participates in a relationship set. Or we can say that the cardinality of a
relationship is the number of tuples (rows) in a relationship.
► A one-to-one :example would be one student associated with one mailing
address.
► A 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.
► Many-to-many :example: Students as a group are associated with multiple faculty
members, and faculty members in turn are associated with multiple students.
Relationship between Cardinality and
Participation Constraints-

► Structural Constraints : Structural Constraints are also called Structural


properties of a database management system (DBMS).
► Cardinality Ratios and Participation Constraints taken together are
called Structural Constraints.
► Minimum cardinality tells whether the participation is partial or total.
► If minimum cardinality = 0, then it signifies partial participation.
► If minimum cardinality = 1, then it signifies total participation.
► Maximum cardinality tells the maximum number of entities that
participates in a relationship set.
Let’s see an example to understand this ER
Model based on the information above.
► Let’s take an e-commerce platform example. The goal is to illustrate how different
components (entities) in a typical e-commerce business can interact with each
other and what kind of attributes they might have. This ER model helps to depict the
logical structure and flow of data in the system.
► Entities
1. Customer
► This entity represents the customers who are using the e-commerce platform.
► Attributes
Cardinality:
Show whether the relationship is 1-1, 1-many or
many-to-many.
[Link]-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.
[Link]-to-many & Many to One

► 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.
► 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.
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.
How to Create an Entity Relationship
Diagram (ERD)
Let’s study them with an Entity
Relationship Diagram Example:
► Step 1) Entity Identification :- Student Course Professor

► Step 2) Relationship Identification : The student is assigned a course


, Professor delivers a course
Step 3) Cardinality Identification
► A student can be assigned multiple courses
A Professor can deliver only one course
Step 4) Identify Attributes

► 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.
Once the mapping is done, identify the primary Keys. If a unique key is not readily available, create one.
Entity Primary Key Attribute
Student Student_ID StudentName
Professor Employee_ID ProfessorName
Course Course_ID CourseName
Step 5) Create the ERD Diagram

► A more modern representation of Entity Relationship Diagram


Example
Bank-details to construct ER-diagram
E-R
diagram
for
Banking
System
How to Draw an ER Diagram?

3. Order
► CustomerID: A unique identifier for each This entity represents the orders placed by
customer registered on the platform. customers on the platform.
► Name: The name of the customer. Attributes
► Email: The email address of the customer. OrderID: A unique identifier for each order
placed on the platform.
► 2. Product OrderDate: The date on which the order
► This entity represents the products available was placed.
for purchase on the platform. CustomerID (Foreign Key): Reference to the
► Attributes CustomerID in the Customer entity to
identify who placed the order.
► ProductID: A unique identifier for each
ProductID (Foreign Key): Reference to the
product listed on the platform.
ProductID in the Product entity to identify
► Name: The name of the product. which product is ordered.
► Price: The price of the product. Quantity: The number of units of the
product ordered.
Relationships

► 1. Places
► This is a relationship between the Customer and Order entities.
► Customers can place multiple orders, thus creating a one-to-many relationship from
Customer to Order.
► 2. Contains
► This is a relationship between the Order and Product entities.
► An order can contain multiple products; similarly, a product can be contained in multiple
orders, establishing a many-to-many relationship.
► This ER model gives a foundational view of how an e-commerce database might be
structured, facilitating various operations like order tracking, inventory management, and
customer relationship management. It helps understand how data is stored, retrieved, and
managed in an e-commerce environment.
E-R diagram Customer- Order

You might also like