2. An entity relationship diagram is a graphicalAn entity relationship diagram is a graphical
representation of an organisation's datarepresentation of an organisation's data
storage requirementsstorage requirements
E-R-D are used to:E-R-D are used to:
Identify the data that must be captured,Identify the data that must be captured,
stored and retrieved in order to supportstored and retrieved in order to support
the businessthe business
Activities performed by an organisationActivities performed by an organisation
Identify the data required to derive andIdentify the data required to derive and
report on the performance measures, thatreport on the performance measures, that
an organisation should be monitoringan organisation should be monitoring
3. Entity relationship diagrams have threeEntity relationship diagrams have three
different components:different components:
ENTITIESENTITIES
ATTRIBUTESATTRIBUTES
RELATIONSHIPSRELATIONSHIPS
4. Entities are the people, places, things,Entities are the people, places, things,
events and concepts of interest to anevents and concepts of interest to an
organisation.organisation.
Represented as RectangleRepresented as Rectangle
• BookBook
• ProjectProject
• PublisherPublisher
• JobJob
• CompanyCompany
• FileFile
EntityEntity
5. AttributeAttribute
Properties or characteristics possessed byProperties or characteristics possessed by
an entity are called as attributesan entity are called as attributes
Represented as ellipse.Represented as ellipse.
Attributes of EMPLOYEE entity set :Attributes of EMPLOYEE entity set :
NameName
AgeAge
Employee_idEmployee_id
SalarySalary
6. DomainDomain
The set of possible values for an attribute isThe set of possible values for an attribute is
called the domain of the attribute.called the domain of the attribute.
The domain of attribute marital status isThe domain of attribute marital status is
just the four values: single, married,just the four values: single, married,
divorced, widowed.divorced, widowed.
The domain of the attribute month is theThe domain of the attribute month is the
twelve values ranging from January totwelve values ranging from January to
December.December.
7. Simple v/s Composite attributeSimple v/s Composite attribute
Simple attributeSimple attribute: An attribute that cannot: An attribute that cannot
be divided into simpler componentsbe divided into simpler components
e.g. age of an employee, pub-id of a book,e.g. age of an employee, pub-id of a book,
title of a book.title of a book.
Composite attributeComposite attribute: An attribute that: An attribute that
can be split into components e.g. Date ofcan be split into components e.g. Date of
joining of the employee can be split intojoining of the employee can be split into
day, month and yearday, month and year
8. Single v/s Multi-valued AttributeSingle v/s Multi-valued Attribute
Single valuedSingle valued : Attributes that can take on: Attributes that can take on
only a single value for each entity instance.only a single value for each entity instance.
e.g. age of employee, pubid of a publishere.g. age of employee, pubid of a publisher
Multi-valuedMulti-valued: Attributes that can take: Attributes that can take
many values for each entity instance.many values for each entity instance.
e.g. skill set of employeee.g. skill set of employee
9. Stored v/s Derived attributeStored v/s Derived attribute
Stored Attribute:Stored Attribute: Attribute that need to beAttribute that need to be
stored permanently.stored permanently.
e.g. : Name of an employeee.g. : Name of an employee
Derived AttributeDerived Attribute: Attribute that can be: Attribute that can be
calculated based on other attributes.calculated based on other attributes.
e.g. : Years of service of employee can bee.g. : Years of service of employee can be
calculated from date of joining and currentcalculated from date of joining and current
datedate
10. AttributesAttributes
K e y A t t r i b u t e M u l t i V a l u e d
A t t r i b u t e
E m p l o y e e S k i l l sE #
N a m e A g e
D O B A d d r e s s
F l o o r
S t r e e t
B u i l d i n g
D e r i v e d
A t t r i b u t e
C o m p o s i t e
A t t r i b u t e
11. RelationshipRelationship
Defines the set of all associations betweenDefines the set of all associations between
two entity types.two entity types.
Represented as RhombusRepresented as Rhombus
Example:Example:
EMPLOYEEs work in a DEPARTMENTEMPLOYEEs work in a DEPARTMENT
LAWYERs advise CLIENTsLAWYERs advise CLIENTs
EQUIPMENT is allocated to PROJECTsEQUIPMENT is allocated to PROJECTs
TRUCK is a type of VEHICLETRUCK is a type of VEHICLE
12. Degree of a RelationshipDegree of a Relationship
The number of entities associated with theThe number of entities associated with the
relationship.relationship.
One – UnaryOne – Unary
employee - manager-of - employeeemployee - manager-of - employee
Two – BinaryTwo – Binary
employee - works-for – departmentemployee - works-for – department
Three – TernaryThree – Ternary
customer – purchase- itemcustomer – purchase- item
16. Cardinality and ConnectivityCardinality and Connectivity
The cardinality of a relationship is theThe cardinality of a relationship is the
actual number of related occurrences foractual number of related occurrences for
each of the two entitieseach of the two entities
–– one-to-one (1:1)one-to-one (1:1)
–– one-to-many (1:N)one-to-many (1:N)
–– many-to- one (M:1)many-to- one (M:1)
–– many-to-many (M:N)many-to-many (M:N)
17. one-to-one (1:1)one-to-one (1:1)
when at most one instance of a entity A iswhen at most one instance of a entity A is
associated with one instance of entity Bassociated with one instance of entity B
E 1
E 2
E 3
E 4
C 1
C 2
C 3
C 4
E M P L O Y E E C H A I R
18. one-to-many (1:N)one-to-many (1:N)
when for one instance of entity A, there are zero, one, orwhen for one instance of entity A, there are zero, one, or
many instances of entity B, but for one instance of entitymany instances of entity B, but for one instance of entity
B, there is only one instance of entity AB, there is only one instance of entity A
O 1
O 2
O 3
E 1
E 2
E 3
E 4
E 5
O R G A N I Z A T I O N E M P L O Y E E
19. many-to- One (M:1)many-to- One (M:1)
When for zero, one or many instances of entity A, thereWhen for zero, one or many instances of entity A, there
is only one instance of entity B , but for one instance ofis only one instance of entity B , but for one instance of
entity B, there is only one instance of entity Aentity B, there is only one instance of entity A
D 1
D 2
D 3
E 1
E 2
E 3
E 4
E 5
D E P A R T M E N TE M P L O Y E E
20. many-to-many (M:N)many-to-many (M:N)
when for one instance of entity A, there are zero, one, orwhen for one instance of entity A, there are zero, one, or
many instances of entity B and for one instance of entitymany instances of entity B and for one instance of entity
B there are zero, one, or many instances of entity AB there are zero, one, or many instances of entity A
P 1
P 2
P 3
P 4
E 1
E 2
E 3
E 4
P R O J E C TE M P O L Y E E
21. CardinalityCardinality
We express cardinality constraints byWe express cardinality constraints by
drawing either a directed line (drawing either a directed line (→→),),
signifying “one,” or an undirected line (—),signifying “one,” or an undirected line (—),
signifying “many,” between thesignifying “many,” between the
relationship set and the entity set.relationship set and the entity set.
22. One-to-One RelationshipOne-to-One Relationship
– A customer is associated with at most oneA customer is associated with at most one
loan via the relationshiploan via the relationship borrowerborrower
– A loan is associated with at most oneA loan is associated with at most one
customer viacustomer via borrowerborrower
23. One-To-Many RelationshipOne-To-Many Relationship
In the one-to-many relationship a loan isIn the one-to-many relationship a loan is
associated with at most one customer viaassociated with at most one customer via
borrowerborrower, a customer is associated with, a customer is associated with
several loans viaseveral loans via borrowerborrower
24. Many-To-One RelationshipsMany-To-One Relationships
In a many-to-one relationship a loan isIn a many-to-one relationship a loan is
associated with several customers viaassociated with several customers via
borrowerborrower, a customer is associated with at, a customer is associated with at
most one loan viamost one loan via borrowerborrower
25. Many-To-Many RelationshipMany-To-Many Relationship
A customer is associated with severalA customer is associated with several
loans via borrowerloans via borrower
A loan is associated with severalA loan is associated with several
customers via borrowercustomers via borrower
26. Participation of an Entity Set inParticipation of an Entity Set in
a Relationship Seta Relationship Set
TotalTotal participationparticipation (indicated by double line): every entity in the entity set(indicated by double line): every entity in the entity set
participates in at least one relationship in the relationship setparticipates in at least one relationship in the relationship set
E.g. participation ofE.g. participation of loanloan inin borrowerborrower is totalis total
every loan must have a customer associated to it via borrowerevery loan must have a customer associated to it via borrower
Partial participationPartial participation: some entities may not participate in any relationship in: some entities may not participate in any relationship in
the relationship setthe relationship set
E.g. participation ofE.g. participation of customercustomer inin borrowerborrower is partialis partial
27. Case Study – ER Model For aCase Study – ER Model For a
college DBcollege DB
Assumptions :Assumptions :
A college contains many departmentsA college contains many departments
Each department can offer any number of coursesEach department can offer any number of courses
Many instructors can work in a departmentMany instructors can work in a department
An instructor can work only in one departmentAn instructor can work only in one department
For each department there is a HeadFor each department there is a Head
An instructor can be head of only one departmentAn instructor can be head of only one department
Each instructor can take any number of coursesEach instructor can take any number of courses
A course can be taken by only one instructorA course can be taken by only one instructor
A student can enroll for any number of coursesA student can enroll for any number of courses
Each course can have any number of studentsEach course can have any number of students
28. Steps in ER ModelingSteps in ER Modeling
Step 1: Identify the EntitiesStep 1: Identify the Entities
Step 2: Find the relationshipsStep 2: Find the relationships
Step 3: Identify the key attributesStep 3: Identify the key attributes
Step 4: Identify other relevant attributesStep 4: Identify other relevant attributes
Step 5: Draw complete E-R diagramStep 5: Draw complete E-R diagram
with all attributes including Primarywith all attributes including Primary
KeyKey
29. Case StudyCase Study
Banking Business ScenarioBanking Business Scenario
Assumptions :Assumptions :
There are multiple banks and each bankThere are multiple banks and each bank
has many branches. Each branch hashas many branches. Each branch has
multiple customersmultiple customers
Customers have various types of accountsCustomers have various types of accounts
Some Customers also had taken differentSome Customers also had taken different
types of loans from these bank branchestypes of loans from these bank branches
One customer can have multiple accountsOne customer can have multiple accounts
and Loansand Loans
30. Step 1: Identify the EntitiesStep 1: Identify the Entities
DEPARTMENTDEPARTMENT
STUDENTSTUDENT
COURSECOURSE
INSTRUCTORINSTRUCTOR
31. Step 2: Find the relationshipsStep 2: Find the relationships
One course is enrolled by multiple students and one student enrollsOne course is enrolled by multiple students and one student enrolls
for multiple courses, hence the cardinality between course andfor multiple courses, hence the cardinality between course and
student is Many to Many.student is Many to Many.
M NM N
The department offers many courses and each course belongs toThe department offers many courses and each course belongs to
only one department, hence the cardinality between department andonly one department, hence the cardinality between department and
course is One to Many.course is One to Many.
1 M1 M
One department has multiple instructors and one instructor belongsOne department has multiple instructors and one instructor belongs
to one and only one department , hence the cardinality betweento one and only one department , hence the cardinality between
department and instructor is one to Many.department and instructor is one to Many.
STUDENTCOURSE ENROLLED BY
DEPARTMENT COURSE
OFFERS
DEPARTMENT INSTRUCTOR
HAS
32. 3232
Step 2: Find the relationships(Cont..)Step 2: Find the relationships(Cont..)
Each department there is a “Head of department” and one instructorEach department there is a “Head of department” and one instructor
is “Head of department “,hence the cardinality is one to one .is “Head of department “,hence the cardinality is one to one .
1 11 1
One course is taught by only one instructor, but the instructorOne course is taught by only one instructor, but the instructor
teaches many courses, hence the cardinality between course andteaches many courses, hence the cardinality between course and
instructor is many to one.instructor is many to one.
M 1M 1
DEPARTMENT INSTRUCTORHEADED BY
COURSE INSTRUCTOR
OFFERS
33. 3333
Deptname is the key attribute for the Entity “Department”,Deptname is the key attribute for the Entity “Department”,
as it identifies the Department uniquely.as it identifies the Department uniquely.
Course# (CourseId) is the key attribute for “Course” Entity.Course# (CourseId) is the key attribute for “Course” Entity.
Student# (Student Number) is the key attribute forStudent# (Student Number) is the key attribute for
“Student” Entity.“Student” Entity.
Instructor Name is the key attribute for “Instructor” Entity.Instructor Name is the key attribute for “Instructor” Entity.
Step 4: Identify other relevant attributesStep 4: Identify other relevant attributes
For the department entity, the relevant attribute is locationFor the department entity, the relevant attribute is location
For course entity, course name, duration,prerequisiteFor course entity, course name, duration,prerequisite
For instructor entity, room#, telephone#For instructor entity, room#, telephone#
For student entity, student name, date of birthFor student entity, student name, date of birth
Step 3: Identify the key attributes
35. Reduction of an E-R SchemaReduction of an E-R Schema
to Tablesto Tables
Converting relationshipsConverting relationships
Unary 1:1 – The primary key fieldUnary 1:1 – The primary key field
itself will become the foreign key initself will become the foreign key in
the tablethe table
36.
37. Converting relationshipsConverting relationships
Binary 1: 1: The primary keyBinary 1: 1: The primary key
of either of the entities canof either of the entities can
become a foreign key in thebecome a foreign key in the
other.other.
38.
39. Converting relationshipsConverting relationships
Binary 1: N: The primary key of theBinary 1: N: The primary key of the
“1” side of the relationship“1” side of the relationship
becomes a foreign key in thebecomes a foreign key in the
relation on the “N” siderelation on the “N” side
40.
41. Converting relationshipsConverting relationships
Binary M: N-Binary M: N-
A new table is created to representA new table is created to represent
relationshiprelationship
Contains two foreign keys – one fromContains two foreign keys – one from
each of participating entitieseach of participating entities
The primary key of new table is theThe primary key of new table is the
combination of two foreign keyscombination of two foreign keys
43. Converting relationshipsConverting relationships
Ternary relationship:Ternary relationship:
A new table is created to representA new table is created to represent
relationshiprelationship
The new table contains three foreign keys-The new table contains three foreign keys-
one from each of the participating entitiesone from each of the participating entities
The primary key of new table is theThe primary key of new table is the
combination of all three foreign keyscombination of all three foreign keys