Entity - Relationship Model - 114914
Entity - Relationship Model - 114914
1
ER model
ER model stands for an Entity-Relationship model.
Entity Relationship Model (ER Modeling) is a graphical
approach to database design.
ER diagram is a conceptual model that gives the
graphical representation of the logical structure of the
database.
ER diagram shows all the constraints and
relationships that exist among the different
components.
E-R model helps us to systematically analyze data
requirements to produce a well-designed database.
It is a high-level data model. This model is used to
define the data elements and relationship for a
specified system.
It develops a conceptual design for the database. It
also develops a very simple and easy to design view
of data. 2
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.
3
E-R Model…
4
Why use ER Diagrams?
• Hidden information: As it is a
high-level view so there are
chances that some details of 7
Components of the ER Diagram
Example
9
What is an Entity?
• An entity is a real-world thing which is distinguishable from other.
• An entity can be place, person, object, event or a concept.
• Every entity is made up of some 'attributes' which represent that
entity.
• It is represented by a rectangle.
Examples:
• Person: Employee, Student, Patient.
• Place: Store, Building.
• Object: Machine, product, and Car.
• Event: Sale, Registration, Renewal.
• Concept: Account, Course.
10
Entity - Set
• An entity set is a collection of similar types of entities.
• For example, a Student’s set may contain all the
students of a college.
Types of Entities
• Strong Entity
− Strong entity is an entity which has a key attribute.
− The primary key helps in identifying each entity
uniquely.
• Weak Entity
− Weak entity type doesn't have a key attribute.
− Weak entity type can't be identified on its own. Its
existence depends upon some other strong entity.
− They are represented with double rectangles.
11
12
Weak Entity Set
An entity set that does not have a primary key.
The existence of a weak entity set depends on another entity.
It must relate to the identifying entity set via a total participation;
one-to-many relationship set from the identifying to the weak entity
set.
The weak entity set has discriminator or partial key.
We depict a weak entity set by double rectangles and underline the
discriminator of a weak entity set with a dashed line.
Weak entity relationship set depicted using double diamonds.
13
Example:
14
What is an attribute?
• An attribute is a property or characteristic of the entity that
holds it.
• For example, a student might have attributes: roll_no, name,
address, phone_no, etc.
• It is represented by an ellipse/oval.
• There exist a specific domain or set of values for each attribute
from where the attribute can take its values.
• For example, a student's name cannot be a numeric value. It
has to be alphabetic. A student's age cannot be negative, etc.
15
Types of attributes
In ER diagram, attributes associated with an entity set may be of
the following types-
1. Simple attribute.
2. Composite attribute.
3. Single valued attribute.
4. Multi valued attribute.
5. Derived attribute.
6. Key attribute.
16
1. Simple attribute
― Simple attributes are atomic values, which cannot be divided
further.
Example:
Here, student’s class, gender, dob are atomic values which can not be
divided further.
17
2. Composite attribute
― A composite attribute is made up of more than one simple
attribute.
― A composite attribute can be further divisible.
Example:
Here, all the attributes are single valued attributes as they can take
only one at a time.
19
4. Multi-Valued Attribute
―These are the attributes which can take more than one
value at a time.
― It is represented by a double ellipse.
Example:
22
Relationship
― A relationship is an association among two or more entities.
― For example, an employee works_at a department, a student
enrolls in a course. Here, Works_at and Enrolls are called
relationships.
― Like entities, a relationship too can have attributes. These
attributes are called descriptive attributes.
23
Relationship Set
―A set of relationships of similar type is called a
relationship set.
Degree of a Relationship
― The number of entity sets that participate in a relationship set is
termed as the degree of that relationship.
― Degree of above relationship is 2.
24
Types of Relationships
― On the basis of degree of a relationship set, a relationship
can be classified into the following types:
1. Unary relationship
2. Binary relationship
3. Ternary relationship
4. N-ary relationship
25
Unary relationship
― When there is a relationship between two entities of the same
type is known as Unary relationship.
― It is known as a recursive relationship.
― This means that the relationship is between different instances of
the same entity type.
― For example: An employee can supervise group of employees.
Hence, this is a recursive relationship of entity employee with itself.
26
Binary Relationship
― When there are exactly two entity sets participating in a
relationship then such type of relationship is called binary
relationship.
― For example, a student enrolls a course, Here, “enrolls” is a
relationship and this is the relationship between a Student
entity and a Course entity.
27
Ternary relationship
― When there are exactly three entity sets participating in a
relationship then such type of relationship is called ternary
relationship
― For example: In the real world, a patient goes to a doctor and
doctor prescribes the medicine to the patient, three entities
Doctor, patient and medicine are involved in the relationship
“prescribes”.
28
N-ary relationship
― When a large number of entity sets are participating in a
relationship, then such type of relationship is called an N-ary
relationship. The N shows the number of entities in the
relationship.
― For example: In the real world, a patient goes to a doctor and
doctor prescribes the diagnosis and medicine to the patient,
four entities Doctor, patient and medicine, diagnostics are
involved in the relationship “prescribes”
29
Mapping Cardinalities / Constraints
― mapping constraint defines how many entities can be
related to another entity to a relationship.
― It is most useful in describing the relationship sets that
involve more than two entity sets.
― For binary relationship set R on an entity set A and B, there
are four possible
― 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)
30
One to One (1:1)
― An entity in A is associated with at most one entity in B, and an
entity in B is associated with at most one entity in A.
― Symbols used:
― For example, Assume that the only male can be married to only
one female and one female can be married to only one male,
this can be viewed as one to one cardinality
31
One to Many (1 : M)
― An entity in A is associated with any (zero or more) entities of B,
and an entity in B can be associated with at most one entity in A.
― Symbol used:
32
Many to One (M: 1)
― An entity in A is associated with atmost one entity in B. and an
entity in B can be associated with any (zero or more) number of
entities in A.
― Symbol used:
― For example: A student can belongs to at most one class but one
class can have many students.
33
Many to Many (M : N)
― An entity in A is associated with any number of entities in B and
an entity in B is associated with any number of entities in A.
― Symbol used:
― For example: Here many books are written by many authors and
many authors write many books.
34
Basic Alternative Cardinality Notation Type
• 1-to-1 relationship
• 1-to-M relationship
• M-to-N relationship
Cardinality con’t
Summary of Relationship Symbols
37
Summary of Relationship Symbols
38
39
Example Model
40
Steps to Create an ER Diagram
1. Entity Identification
2. Relationship Identification
3. Cardinality Identification
4. Attribute Identification
5. Draw ER diagram
41
Example 1
42
Example 2
• A sales representative must write
many invoices. Each invoice has to be
written by one sales representative.
• Each sales representative must be
assigned to many department. Each
department has only one sales
representative.
• A customer has to generate many
invoices. An invoice is generated by
only one customer.
43
ER-DIAGRAM SCENARIOS
Scenario 1
UPS prides itself on having up-to-date information on the
processing and current location of each shipped item. To
do this, UPS relies on a company-wide information system.
Shipped items are the heart of the UPS product tracking
information system. Shipped items can be characterized by
item number (unique), weight, dimensions, insurance
amount, destination, and final delivery date. Shipped
items are received into the UPS system at a single retail
centre. Retail centres are characterized by their type,
uniqueID, and address. Shipped items make their way to
their destination via one or more standard UPS
transportation events (i.e., flights, truck deliveries).
These transportation events are characterized by a unique
scheduleNumber, a type (e.g, flight, truck), and a
deliveryRoute. Required to:
a) Identify the Entity Types and their possible attributes
b) Identify the possible Relationships
c) Draw an E-R diagram for the given scenario
d) Construct appropriate tables for the E-R diagram 44
Scenario 2:
A university consists of a number of departments. Each
department offers several courses. A number of modules
make up each course. Students enroll in a particular
course and take modules towards the completion of that
course. Each module is taught by a lecturer from the
appropriate department, and each lecturer tutors a group
of students. Required to:
45
Scenario 3:
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. Required
to:
a) Identify the Entity Types and their possible
attributes
b) Identify the possible Relationships
c) Draw an E-R diagram for the given scenario
d) Construct appropriate tables for the E-R
diagram
46
Thank you
47