100% found this document useful (1 vote)
72 views13 pages

Entity-Relationship (E/R) Model

The document discusses the Entity-Relationship (E-R) model, a conceptual data model used to describe a database at the requirements stage. It describes key concepts of the E-R model including entities, attributes, relationships, and diagrammatic notation. Entities can have simple, composite, single-valued, and multi-valued attributes. Relationships associate entities and have a cardinality ratio like one-to-one, one-to-many, many-to-one, or many-to-many. The E-R model provides a rigorous yet understandable way to conceptualize a database before implementation.

Uploaded by

Khushboo Agarwal
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)
72 views13 pages

Entity-Relationship (E/R) Model

The document discusses the Entity-Relationship (E-R) model, a conceptual data model used to describe a database at the requirements stage. It describes key concepts of the E-R model including entities, attributes, relationships, and diagrammatic notation. Entities can have simple, composite, single-valued, and multi-valued attributes. Relationships associate entities and have a cardinality ratio like one-to-one, one-to-many, many-to-one, or many-to-many. The E-R model provides a rigorous yet understandable way to conceptualize a database before implementation.

Uploaded by

Khushboo Agarwal
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
You are on page 1/ 13

26/01/20

Entity-Relationship
(E/R) Model

Dr P Sreenivasa Kumar
Professor
CS&E Dept I I T Madras

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.

Prof P Sreenivasa Kumar 2


Department of CS&E, IITM

Entities
§  Entity - a thing (animate or inanimate) of independent
physical or conceptual existence and distinguishable.
In the University database context, an individual
student, faculty member, a class room, a course
are entities.

§  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.

Prof P Sreenivasa Kumar 3


Department of CS&E, IITM

1
26/01/20

Attributes
Each entity is described by a set of attributes/properties
that have associated values

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.

Prof P Sreenivasa Kumar 4


Department of CS&E, IITM

Types of Attributes (1/2)


•  Simple Attributes
§  having atomic or indivisible values.
example: Dept – a string
PhoneNumber – a ten 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: Age depends on DateOfBirth.
So age is a derived attribute.

Prof P Sreenivasa Kumar 5


Department of CS&E, IITM

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 student
EmailAddress attribute for student
PreviousDegree attribute for student.
•  Attributes can be:
§  simple single-valued, simple multi-valued,
§  composite single-valued or composite multi-valued.

Prof P Sreenivasa Kumar 6


Department of CS&E, IITM

2
26/01/20

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

Fname Mname
Lname
Program
RollNumber

StudName
Student AdmissionYear
Sex

Age EmailAddress
DateOfBirth

Prof P Sreenivasa Kumar 7


Department of CS&E, IITM

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

Prof P Sreenivasa Kumar 8


Department of CS&E, IITM

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
Prof P Sreenivasa Kumar 9
Department of CS&E, IITM

3
26/01/20

Relationships

•  When two or more entities are associated with each other,


we have an instance of a Relationship.
•  E.g.: student Ramesh 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.

Prof P Sreenivasa Kumar 10


Department of CS&E, IITM

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.

Prof P Sreenivasa Kumar 11


Department of CS&E, IITM

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.

A B
R

Prof P Sreenivasa Kumar 12


Department of CS&E, IITM

4
26/01/20

Binary Relationships and Cardinality Ratio

M N
E1 R E2

•  The maximum 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)

Prof P Sreenivasa Kumar 13


Department of CS&E, IITM

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: An E2 entity may be associated with
many E1 entities whereas an E1 entity may
be associated with at most one E2 entity.
•  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.

Prof P Sreenivasa Kumar 14


Department of CS&E, IITM

One-to-many
E1 E2 E1 One-to-one E2

Many-to-one
E1 E2 E1 Many-to-many E2

Prof P Sreenivasa Kumar 15


Department of CS&E, IITM

5
26/01/20

Cardinality Ratio – example (one-to-one)

Name Phone CourseID Name


1 1
Sex Professor Teaches Course Credits

Address

HostelName
Name
RoomNo
1 1 Hostel
RollNo Student ResidesIn Room

Address

Prof P Sreenivasa Kumar 16


Department of CS&E, IITM

Cardinality Ratio – example (many-to-one/one-to-many)

Name Location
Name Phone
N 1
Sex Professor belongsTo Department

(many-to-one)
Address

Name RoomNo
Name Phone
1 N
guides Student
Sex Professor

Address Address (one-to-many)

Prof P Sreenivasa Kumar 17


Department of CS&E, IITM

Cardinality Ratio – example (many-to-many)

Name RollNo
Name
CourseId
Student enrolls Course
M N
Address
Credits

Name Phone Name Sponser

Professor worksFor SponsoredProject


Sex
M N

Value Duration
Address
Start End
Date Date

Prof P Sreenivasa Kumar 18


Department of CS&E, IITM

6
26/01/20

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:

E1 R E2

total partial

Prof P Sreenivasa Kumar 19


Department of CS&E, IITM

Example of total/partial Participation

Name Location
Name Phone
N 1
Sex Professor belongsTo Department

(many-to-one)
Address

Name RoomNo
Name Phone
1 N Student
Sex Professor guides

Address Address
one-to-many

Prof P Sreenivasa Kumar 20


Department of CS&E, IITM

Structural Constraints
•  Cardinality Ratio and Participation Constraints are together
called Structural Constraints.
•  They are called constraints as the data must satisfy them to be
consistent with the requirements.
•  Min-Max notation: pair of numbers (m,n) placed on the line
connecting an entity to the relationship.
•  m: the minimum number of times a particular entity must
appear in the relationship tuples at any point of time
•  0 – partial participation
•  ≥ 1 – total participation
•  n: similarly, the maximum number of times a particular entity
can appear in the relationship tuples at any point of time

Prof P Sreenivasa Kumar 21


Department of CS&E, IITM

7
26/01/20

Comparing the Notations


N 1
E1 R E2

is equivalent to

(1,1) (0,N)
E1 R E2

Many-to-one
E1 E2

Prof P Sreenivasa Kumar 22


Department of CS&E, IITM

Attributes for Relationship Types


Relationship types can also have attributes.
§  properties of the association of entities.

M N
Student enrolls Course

Grade

§  grade gives the letter grade (S,A,B, etc.) earned by


the student for a course.
§  neither an attribute of student nor that of course.

Prof P Sreenivasa Kumar 23


Department of CS&E, IITM

Attributes for Relationship Types – More Examples

N 1
Professor belongsTo Department

joinDate

M N
Professor worksFor SponsoredProject

percentTime

Prof P Sreenivasa Kumar 24


Department of CS&E, IITM

8
26/01/20

Recursive Relationships and Role Names

•  Recursive relationship: An entity set relating to itself


gives rise to a recursive relationship
•  E.g., the relationship prereqOf is an example of a recursive
relationship on the entity Course
•  Role Names – used to specify the exact role in which the
entity participates in the relationships
•  Essential in case of recursive relationships
•  Can be optionally specified in non-recursive cases
prerequisite
prereqOf

Course
course
Role Names
Prof P Sreenivasa Kumar 25
Department of CS&E, IITM

Weak Entity Sets


Weak Entity Set: An entity set whose members owe their
existence to some entity in a strong entity set.
§  weak entities are not of independent existence.
§  each weak entity is associated with some entity of the
owner entity set through a special relationship
§  weak entity set may not have a key attribute
§  the owner entity might itself be a weak entity
§  identifying relationship may not always be binary

Double wall
S R W box

Always total
Owner entity
Identifying relationship
Prof P Sreenivasa Kumar 26
Department of CS&E, IITM

Weak Entity Sets - Example


Year
SectionNo
Name SemesterNo

has Section RoomNo


CourseID Course
Section

Credits Professor ClassTime

A popular course may have


Partial key:
several sections each taught Uniquely identifies a section
by a different professor and among the set of sections
having its own class room of a particular course
and meeting times

Prof P Sreenivasa Kumar 27


Department of CS&E, IITM

9
26/01/20

Weak Entity Sets – Another Example


Charge
usageNo
Name Date

Equipment utility Usage Time


EquipID

Cost User Dept

Institute has many pieces of equipment


and we like to keep track of their
utilization. Keeping track of the usage is
Partial key:
relevant only when the equipment exists! Uniquely identifies a usage
among the set of uses
of a particular equipment

Prof P Sreenivasa Kumar 28


Department of CS&E, IITM

Complete Example for E/R schema: Specifications (1/2)


In an educational institute, there are several departments and each
student belongs to one of them. Each department has a unique
department number, a name, a location, phone number and is
headed by a professor. Professors have a unique employee Id,
name and a phone number. A professor works for exactly one
department.
We like to keep track of the following details regarding students:
name, unique roll number, sex, phone number, date of birth,
age and one or more email addresses. Students have a local
address consisting of the hostel name and the room number.
They also have home address consisting of house number,
street, city and PIN. It is assumed that all students reside in the
hostels.

Prof P Sreenivasa Kumar 29


Department of CS&E, IITM

Complete Example for E/R schema: Specifications (2/2)


A course taught in a semester of the year is called a section. There
can be several sections of the same course in a semester; these
are identified by the section number. Each section is taught by a
professor and has its own timings and a room to meet. Students
enroll for several sections in a semester.
Each course has a name, number of credits and the department that
offers it. A course may have other courses as pre-requisites i.e,
courses to be completed before it can be enrolled in.
Professors also undertake research projects. These are sponsored
by funding agencies and have a specific start date, end date and
amount of money given. More than one professor can be
involved in a project. Also a professor may be simultaneously
working on several projects. A project has a unique projectId.

Prof P Sreenivasa Kumar 30


Department of CS&E, IITM

10
26/01/20

Entities - Student

HNo Street
City
HostelName
EmailId PIN
Address
RoomNo
RollNo ess
ddr
alA
Loc
Name Student
DateOfBirth

Age
Sex

Prof P Sreenivasa Kumar 31


Department of CS&E, IITM

Entities – Department and Course

Location Credits
Name CourseID Name
Phone

HOD
Department Course

DeptNo

Prof P Sreenivasa Kumar 32


Department of CS&E, IITM

Entities – Professor, Project and Sections

Professor Project Sponsor


Name

ProfID Amount
PhoneNumber
StartDate EndDate

ProjectId

Section

Timing

SectionID ClassRoom

Prof P Sreenivasa Kumar 33


Department of CS&E, IITM

11
26/01/20

E/R Diagram showing relationships

N 1
Student belongs Department
M
To
1
1
enrolls works
ers For
N off
N
N
1
Course 1 Professor
M N M

hasSection teaches
prerequisite works
Of
N
On
N N
Section Project

Prof P Sreenivasa Kumar 34


Department of CS&E, IITM

Design Choices: Attribute versus Relationship

•  Should offering department be an attribute of a course or


should we create a relationship between Course and Dept
entities called, say, offers ?
•  Later approach is preferable when the necessary entity,
in this case the Department, already exists.
•  Should class room be an attribute of Section or
should we create an entity called ClassRoom and
have a relationship, say, meetsIn, connecting Section
and ClassRoom?
•  In this case, the option of making classRoom as an attribute
of Section is better as we do not want to give a lot of
importance to class room and make it a an entity.

Prof P Sreenivasa Kumar 35


Department of CS&E, IITM

Design Choices:

Weak entity versus composite multi-valued attributes

•  Note that a section could also be modeled as a composite multi-


valued attribute of Course entity.
•  However, if so, section can not participate in relationships,
such as, enrolls with Student entity.
•  In general, if a thing, even though not of independent existence,
participates in other relationships on its own, it is best
captured as a weak entity.
•  If the above is not the case, composite multi-valued
attribute may be enough.

Prof P Sreenivasa Kumar 36


Department of CS&E, IITM

12
26/01/20

Ternary Relationships
Relationship instance (c, p, j) in supply indicates that
company c supplies a component p that is made use of by the project j

canSupply

Company supply Component

ser s
ve
s use

Example from Project


Elmasri & Navathe
Fund. of DB Systems
Prof P Sreenivasa Kumar 37
Department of CS&E, IITM

Ternary Relationships
(c,p) in canSupply, (j,p) in uses, (c,j) in serves may not together imply (c,p,j) is
in supply. Whereas the other way round is of course true.

canSupply

Company supply Component

ser s
ve
s use The binary
relationships
together do not
Example from Project convey the
Elmasri & Navathe same meaning
as supply
Fund. of DB Systems
Prof P Sreenivasa Kumar 38
Department of CS&E, IITM

13

You might also like