NI_DBMS_ER Model 2024
NI_DBMS_ER Model 2024
Entity-Relationship Modeling
N. Ilayaraja
PSG Tech.
1
Introduction
A data model is an integrated collection of concepts that represents real
world objects, events, and their relationships
– There are two types of data models:
Object-based data models ( ER Model, Object-oriented model )
Relation-based data models (Relational Model, Network Model, Hierarchical
Model)
2
Types of Data Models
3
The Entity-Relationship Model
An entity-relationship model describes data in terms of the following:
– Entities
– Relationship between entities
– Attributes of entities
4
What is it about?
ER model is used to show the Conceptual schema of an organisation.
5
Entity Relationship Model at levels
of Abstraction
Conceptual data model
• Conceptual ERD models the business objects that should exist in a system and
the relationships between them. A conceptual model is developed to present an
overall picture of the system by recognizing the business objects involved. It
defines what entities exist.
Logical data model
– Examples:
Person: Student, Employee, Client
Object: Couch, Airplane, Machine
Place: City, Park, Room, Warehouse
Event: War, Marriage, Lease
Concept: Project, Account, Course
10
Entities
Entity - distinguishable “thing” in the real world
An entity set is a set of entity instances which all are sharing the
common properties/attributes ( not attributes values).
Example:
– Entity type: STUDENT
– Entity instance: Student with ID number 24MX101, Name ABI
– Entity set: Collection of all students
13
Attributes
An attribute is a property or characteristic of an entity type
– We represent an entity with a set of attributes
– Used to describe entities
– Examples:
STUDENT = {Student ID, SSN, Name, Address, Phone, Email, DOB}
ORDER = {Order ID, Date of Order, Amount of Order}
ACCOUNT = {Account Nr, Account type, Balance}
CITY = {Name, State, Population}
– Attributes Types:
Simple, composite, single-valued, multi-valued, stored, and derived
14
Attributes
Attributes can be
– simple (atomic) e.g. Surname; date of birth
– Composite e.g. address (street, town, postcode)
– Multi-valued e.g. phone number
– Complex nested multi-valued and composite
– Base or Derived e.g. DOB is a Base; age is a derived
– Key e.g. Rollno, EmpId; Foreign Key
Attributes in E-R Diagram
16
Attributes in E-R Diagram
birthday
id
ACTOR
name address
17
Another Option for a Key?
birthday
id
Actor
name address
18
Simple and Composite Attributes
A simple or an atomic attribute cannot be further divided into smaller
components
– Examples:
City
State
19
Single-Valued and Multi-Valued Attributes
Single-valued attributes have a single value for an entity instance
– Examples:
Major
Date Of Birth
Multi-valued attributes, on the other hand, may have more than one
value for an entity instance
– Denoted with a double-lined ellipse
– Example:
Languages: Stores the names of the languages that a student speaks
21
Stored and Derived Attributes
The value of a derived attribute can be determined by analyzing other
attributes
– Therefore, no need to store them in the database directly
– Example:
Age: Can derived from the current date and the attribute DateOfBirth
24
Key Attribute
A key attribute (or identifier) is a single attribute or a combination of
attributes that uniquely identify an individual instance of an entity type
– Underlined in an E-R diagram
– Example:
Student: StudentID
26
Candidate Key Attribute
Sometimes no single attribute can uniquely identify an instance of an
entity type
– Example:
City: {Name, State}
27
Relationships
A relationship is an association / binding / links / bonds among several
entities ( entity types)
Examples:
– STUDENT “takes” COURSES
– CUSTOMER “has” ACCOUNT
– CUSTOMER “books” TICKET
– FACULTY “assign to “ CABIN
Represented by diamond shaped box connected to relating entities
28
Overview – Part 1
3.1 Introduction
3.2 The Entity-Relationship Model
3.3 Entity
3.4 Attributes
3.5 Relationships
3.6 Degree of a Relationship
3.7 Cardinality of a Relationship
3.8 Unary Relationship
3.9 Binary Relationship
3.10 Ternary Relationships
3.11 Attributes of Relationships
3.12 Associative Entities
3.13 Weak Entity Types
29
Degree of a Relationship
The number of entity sets that participate in a relationship is called the
degree of relationship
– Binary (degree 2)
An association between two instances of two different types
R є E1 x E2
– Ternary (degree 3)
An association between three instances of three different types
R є E1 x E2 x E3
30
Cardinality of a Relationship
Maximum cardinality represents the maximum number of instances of
entity B that can be associated with any instance of entity A
31
Maximum Cardinality
Relationship types by maximum cardinality:
– One-to-One
– One-to-Many (and vice-versa)
– Many-to-Many
One Many
32
Minimum Cardinality
The minimum cardinality of a relationship is defined as the minimum
number of instances of entity B that must be associated with each
instance of entity A
Optional
Mandatory
33
Unary Relationships - Examples
One-to-One
One-to-One
Many-to-Many
34
Recursive Unary Relationships
phone
number
manager
id
Employee Manages
worker
name
address
35
Binary Relationships - Examples
One-to-One
One-to-Many
Many-to-Many
36
Example
title
birthday
id
Actor Acted In Film year
name
address type
38
Ternary Relationships - Examples
Musical Performance
Example
Student “Uses”
Equipment for a
Project Example
39
Ternary Relationships - Examples
id Director name
id
Actor Produced Film title
name
40
Ternary relationships
42
One-to-Many
A film is directed by at most one director
A director can direct any number of films
id
Director Directed Film title
name
id
Director Directed Film title
name
id
Director Directed Film title
name
Here,max
cardinality
constraint is 4
Attributes of Relationships
An attribute on a relationship stores information related to the
relationship is known as “Descriptive Attribute”
– Much like attributes on entity types
Relationship
Attribute
52
Associative Entities
An entity–has attributes
A relationship–links entities together
When should a relationship with attributes instead be
an associative entity?
– All relationships for the associative entity should be many
– The associative entity could have meaning independent of the other
entities
– The associative entity preferably has a unique identifier, and should
also have other attributes
– The associative entity may participate in other relationships other
than the entities of the associated relationship
– Ternary relationships should be converted to associative entities
53
Associative Entities
An associative entity is an entity type that connects the instances of
one or more entity types and contains attributes particular to this
association
– Allows us to store data from relationship attributes more effectively
54
A binary relationship with an attribute
55
An associative entity (CERTIFICATE)
56
Associative Entities – Example 1
57
Associative Entities – Example 2
Ternary Relationship
Weak
Entity
59
Strong vs. Weak Entities, and
Identifying Relationships
Strong entities:
•exist independently of other types of entities
•has its own unique identifier
•identifier underlined with single-line
Weak entity:
•dependent on a strong entity (identifying owner)…cannot exist
on its own
•does not have a unique identifier (only a partial identifier)
•Partial identifier underlined with double-line
•Entity box has double line
Identifying relationship:
•links strong entities to weak entities
60
Identifying relationship
61
Strong entity Identifying relationship Weak entity
62
Existence Dependencies
The discriminator (or partial key) of a weak entity set is the set of
attributes that distinguishes among all the entities of a weak entity set.
The primary key of a weak entity set is formed by the primary key of the
strong entity set on which the weak entity set is existence dependent,
plus the weak entity set’s discriminator.
64
Weak Entity Sets
We depict a weak entity set by double rectangles.
We underline the discriminator of a weak entity set with a
dashed line.
payment-number – discriminator of the payment entity set
Primary key for payment – (loan-number, payment-
number)
Weak Entity
66
Example 1
A publishing company produces scientific books on various subjects. The
books are written by authors who specialize in one particular subject. The
company employs editors who, not necessarily being specialists in a
particular area, each take sole responsibility for editing one or more
publications.
A publication covers essentially one of the specialist subjects and is
normally written by a single author. When writing a particular book, each
author works with on editor, but may submit another work for publication to
be supervised by other editors. To improve their competitiveness, the
company tries to employ a variety of authors, more than one author being a
specialist in a particular subject.
Example 1 - answer
concerns edited by
Subject Publication
is specialised in
is written by
Editor
Author
Author-
works with Editor employs
Example 2
A General Hospital consists of a number of specialized wards (such as
Maternity, Paediatry, Oncology, etc). Each ward hosts a number of patients,
who were admitted on the recommendation of their own GP and confirmed
by a consultant employed by the Hospital. On admission, the personal
details of every patient are recorded. A separate register is to be held to
store the information of the tests undertaken and the results of a prescribed
treatment.
g iv es Tests
is ad mitted to
Test-Results sp ecialised in
Treatment
fo llo w s d ev is es
g ets
reco mmen d s
as sig n ed to
0
GP
Consultant