Entity-Relationship
(E/R) Model
Ali Akbar Mohammadi
Entity-Relationship (E/R) Model
• Widely used conceptual level data model
• Proposed by Peter P Chen in 1970s
• Data model to describe the database system at the requirements
collection stage
• High level description.
• Easy to understand for the enterprise managers.
• Rigorous enough to be used for system building.
• Concepts available in the model
• Entities and attributes of entities.
• Relationships between entities.
• Diagrammatic notation.
Ali Akbar Mohammadi 2
Entities
• Entity: A thing (animate or inanimate) of independent physical or
conceptual existence and distinguishable.
• For example in the University database context, an individual student,
faculty member, a class room, a course are entities.
Ali Akbar Mohammadi 3
Entity Set or Entity Type
• Collection of entities all having the same properties.
• Student entity set –collection of all student entities.
• Course entity set –collection of all course entities.
Ali Akbar Mohammadi 4
Attributes
• Each entity is described by a set of attributes/properties.
• student entity
• StudName–name of the student.
• RollNumber–the roll number of the student.
• Sex–the gender of the student etc.
• All entities in an Entity set/type have the same set of attributes.
• Chosen set of attributes –amount of detail in modeling.
Ali Akbar Mohammadi 5
Types of Attributes (1/2)
• Simple Attributes
• Having atomic or indivisible values.
example: Dept–a string
• PhoneNumber–an eight digit number
• Composite Attributes
• Having several components in the value.
example: Qualification with components
• (DegreeName, Year, UniversityName)
• Derived Attributes
• Attribute value is dependent on some other attribute.
example:Agedepends on DateOfBirth.
• So age is a derived attribute.
Ali Akbar Mohammadi 6
Types of Attributes (2/2)
• Single-valued
• having only one value rather than a set of values.
• for instance, PlaceOfBirth–single string value.
• Multi-valued
• having a set of values rather than a single value.
• for instance, CoursesEnrolled attribute for studentEmailAddress attribute for
studentPreviousDegree attribute for student.
• Attributes can be:
• simple single-valued, simple multi-valued, composite single-valued or
composite multi-valued.
Ali Akbar Mohammadi 7
Diagrammatic Notation for
Entities
• entity -rectangle
• attribute -ellipse connected to rectangle
• multi-valued attribute -double ellipse
• composite attribute -ellipse connected to ellipse
• derived attribute-dashed ellipse
Ali Akbar Mohammadi 8
Diagrammatic Notation for
Entities
Ali Akbar Mohammadi 9
Domains of Attributes
Each attribute takes values from a set called its domain
For instance, studentAge–{17,18, …, 55}
HomeAddress–character strings of length 35
Domain of composite attributes –
cross product of domains of component attributes
Domain of multi-valued attributes –
set of subsets of values from the basic domain
Ali Akbar Mohammadi 10
Entity Sets and Key Attributes
• Key–an attribute or a collection of attributes whose value(s) uniquely identify an
entity in the entity set.
• For instance,
• RollNumber-Key for Student entity set
• EmpID-Key for Faculty entity set
• HostelName, RoomNo-Key for Student entity set(assuming that each student gets to stay in a
single room)
• A key for an entity set may have more than one attribute.
• An entity set may have more than one key.
• Keys can be determined only from the meaning of the attributes in the entity type.
• Determined by the designers
Ali Akbar Mohammadi 11
Relationships
• When two or more entities are associated with each other, we have
an instance of a Relationship.
• E.g.: student Ali enrolls in Discrete Mathematics course
• Relationship enrolls has Student and Course as the participating entity
sets.
• Formally, enrolls ⊆Student ×Course
• (s,c) ∈enrolls ⇔ Student ‘s’ has enrolled in Course ‘c’
• Tuples in enrolls–relationship instances
• Enrolls is called a relationship Type/Set.
Ali Akbar Mohammadi 12
Degree of a Relationship
• Degree: the number of participating entities.
• Degree 2: binary
• Degree 3: ternary
• Degree n: n-ary
• Binary relationships are very common and widely used
Ali Akbar Mohammadi 13
Diagrammatic Notation for
Relationships
• Relationship –diamond shaped box
• Rectangle of each participating entity is connected by a line to this diamond.
Name of the relationship is written in the box.
Ali Akbar Mohammadi 14
Binary Relationships and
Cardinality Ratio
• The number of entities from E2 that an entity from E1 can possibly be
associated thru R(and vice-versa) determines the cardinality ratio of
R.
• Four possibilities are usually specified:
• one-to-one (1:1)
• one-to-many (1:N)
• many-to-one (N:1)
• many-to-many (M:N)
Ali Akbar Mohammadi 15
Cardinality Ratios
• One-to-one: An E1 entity may be associated with at most
one E2 entity and similarly an E2 entity may be
associated with at most one E1 entity.
• One-to-many: An E1 entity may be associated with many
E2 entities whereas an E2 entity may be
associated with at most one E1 entity.
• Many-to-one: …( similar to above)
• Many-to-many: Many E1 entities may be associated with a
single E2 entity and a single E1 entity may be
associated with many E2 entities.
Ali Akbar Mohammadi 16
Cardinality Ratio –example (one-
to-one)
Ali Akbar Mohammadi 17
Cardinality Ratio –example
(many-to-one/one-to-many)
Ali Akbar Mohammadi 18
Cardinality Ratio –example
(many-to-many)
Ali Akbar Mohammadi 19
Participation Constraints
• An entity set may participate in a relation either totally or partially.
• Total participation: Every entity in the set is involved in some
association (or tuple) of the relationship.
• Partial participation: Not all entities in the set are involved in
association (or tuples) of the relationship.
• Notation:
Ali Akbar Mohammadi 20
Example of total/partial
Participation
Ali Akbar Mohammadi 21