Professional Documents
Culture Documents
Database Management Systems: Entity Relationship Diagram
Database Management Systems: Entity Relationship Diagram
Database Management Systems: Entity Relationship Diagram
pus
ru Cam
al u
ng
Database Management Systems tha m, Be
ee
id yap
a V
r
Chapter 2
ita
Vi shw
Entity
© Relationship Diagram
Am
1
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
© Am
r ita
Vi shwa Vid
yap
eetha m, Bengal uru
Cam
pus
2
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
3
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Why use ER Diagrams?
ER Diagram is allowed you to communicate with the logical structure
p s
u of the
Ca m
database to users
uru al
eng
, B
ha m what fields are going to
Provide a preview of how all your tables should connect,
eet
be on each table
ya p
Vid
wa
i sh
ER diagrams are translatable ta V relational tables which allows you to build
into
databases quickly m ri
©A
The database designer gains a better understanding of the information to be
contained in the database with the help of ER diagram
4
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
What is an
Attribute…….?????
5
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
©
Attributes
Am
r ita
Vi shwa Vid
yap
eetha m, Bengal uru
Cam
pus
Student
Entity Set
6
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Entity:
• Entity is any real world object with well defined property.
pus
Cam
l uru
n ga
• An Entity can be a thing, person, place, , Be unit, object or any
ha m
item about which the data should eetbe captured and stored in
ya p
Vid
the form of properties anda tables.
i shw
ta V
mri
A
• Entity without©properties is not an entity.
7
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Examples of Entities: us
p
ru Cam
• Person: Employee, Student, Patient gal u
Ben
m,
ha
• Place: Store, Building eet
yap
id
a V
• Object: Machine, product,i s w
h and Car
ta V
mri
A
• Event: Sale, Registration, Renewal
©
• Concept: Account, Course
8
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Entity:
pus
• Table / Table Name -----> Entity ru Cam
al u
ng
, Be
ha m
• Column -----> eet
Attributes
ya p
Vid
wa
i sh
• Connection between V
r ita tables -----> Relationship
m
©A
9
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Example
10
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
© Am
r ita
Vi shwa Vid
yap
eetha m, Bengal uru
Cam
pus
11
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Example:
Two Entities: Student and College and their relationship.
pus
Student entity has attributes such as Stu_Id, Stu_Name & Stu_Addr and
College entity has attributes such as Col_ID & Col_Name. ru Cam
al u
n g
, Be
h
The relationship between Student and College is that the students study inm
a colleges.
e e t
ya p
V id
a
i shw
ta V
m ri
©A
12
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Rectangle: Represents Entity sets.
13
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Lines: They link attributes to Entity Sets
& Entity sets to Relationship Set /
Partial participation of an entity in a
relationship
Double Lines: Total participation of an pus
entity in a relationship
ru Cam
al u
Cardinality: specifies how many eng
instances of an entity relate to one 1:1 , 1:M / M:1, M:N m, B
instance of another entity. tha
p ee
id ya
a V
In some cases, entities can be self- i shw
V
linked. For example, employees can
r ita
supervise other employees.
© Am
14
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
15
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Attributes:
There are four types of attributes: us
p
ru Cam
al u
1. Key attribute-uniquely identifies each row inenagtable
, B
Stud(regno, name, ph. No, dob, age) etham
a pe
2. Composite attribute ----- simpleid y
a V
i shw
ta V
ri ------single valued/atomic
3. Multivalued attribute
m
© A 1 A 100
2 A 101,102
4. Derived attribute----stored
16
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
1. Key attribute:
• A key attribute can uniquely identify an entity from an entity set.
p us
ama set of students.
• For example, student roll number can uniquely identify a student ufrom
C
al ur
eng
B however the text of key
• Key attribute is represented by oval same as other attributes
,
ha m
attribute is underlined. eet
ya p
Vid
wa
i sh
ta V
mri
©A
17
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
2. Composite attribute:
• An attribute that is a combination of other attributes is known as composite attribute.
pus
am as an address is
• For example, In student entity, the student address is a compositeuattribute
C
composed of other attributes such as pin code, state, country.al ur
eng
, B
ha m
eet
ya p
Vid
wa
i sh
ta V
m ri
©A
Pin code
State
Country 18
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
3. Multivalued attribute:
• An attribute that can hold multiple values is known as multivalued attribute.
• It is represented with double ovals in an ER Diagram. pus
ru Cam
• For example – A person can have more than one phone numbers al u so the phone number
ng
attribute is multivalued. , Be
ha m
eet
ya p
Vid
wa
i sh
ta V
mri
©A
19
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
4. Derived attribute:
• A derived attribute is one whose value is dynamic and derived from
pus
another attribute. It is represented by dashed oval in an ERaDiagram.
m
ru C
l u
• For example – Person age is a derived attribute asngita changes over time
, Be
and can be derived from another attribute h(Date a m of birth).
eet
ya p
Vid
wa
i sh
ta V
m ri
©A
20
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
pus
Mapping Cardinality / Cardinality Ratio / Cardinality :
ru Cam
al u
Specifies how many instances of an entity relate to how many instance of another entity
.
ng
, Be
ha m
eet
• There are four types of Mapping Cardinalities: y a p
V id
1. One to One w a
i sh
t a V
2. One to Many m ri
© A
3. Many to One
4. Many to Many
21
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
22
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
A3 CCC
23
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
• One to Many ( 1: M)
pus
Cam
When a single instance of an entity is associated with more l uru than one
instances of another entity then it is called one to many nga relationship.
, Be
For example – a customer can place many orders ha m but a order cannot be
placed by many customers. eet
ya p
Cust(c1,c2) Ord(o1,o2,o3) c1:o1,o2 Vid c2:o3 1:m
a
i shw
ta V o1: C1, o2: c1, o3:c2 1 :1
r i
m
©A
24
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
25
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
• Many to One ( M: 1)
When more than one instances of an entity is associated with a psingleus
am
instance of another entity then it is called many to one relationship.
C
l uru
For example – many students can study in a single collegenga but a student
cannot study in many colleges at the same time. , Be
ha m
eet
ya p
Vid
wa
i sh
ta V
m ri
©A
26
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
• Many to One ( M: 1)
pus
Cam
ru
StudColl 1:1 al u
ng
Stud Coll M:1 , Be
ha m
eet
M:1 a p
id y
S1-c1 s2-c1 s3-c3 1:1 V
a c1-s1,s2 c2-s3 c3- 1:M
i s w
hColl Code
Reg No Name V
r ita c1
S1 AAA
© Am
S2 BBB
c2
S3 CCC
c3
27
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
• Many to Many ( M: N)
When more than one instances of an entity is associated with more pus than one
am
instances of another entity then it is called many to many urelationship.
C
al ur
eng
, B
For example, a can be assigned to many projects ha m and a project can be
assigned to many students. eet
ya p
Vid
a
i shw
ta V
m ri
©A
28
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
• Many to Many ( M: N)
StudProject 1:M us
p
Stud Project M:1 ru Cam
al u
M: M / M:N ng
, Be
ha m
S1- P1,P2 S2 - P1 S3 - P2, P3 eet
id yap
a V
i s w
hPjt Code
Reg No Name V
S1 AAA r ita P1
S2 BBB © Am
S3 CCC P2
P3
29
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
• Many to Many ( M: N)
Studcourse 1:M us
p
Stud course M:1 Cam
l uru
M: M / M:N n ga
, Be
S1-DB,OOPs S2-DB S3- Oops, PR 1:M(1 stud ha m reg multiple courses)
e t
e course is reg by multiple stud)
DB-s1,s2 Oops-s1,s3 PR –S3 1:M(1 ya p
V id
w a
i shcourse
Reg No Name
ta V
S1 AAA
mri DB
S2 BBB ©A
S3 CCC OOPs
PR
30
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
pus
Participation Constraints : ru Cam
al u
Specifies if all the instances or only few of the instances of an entity are participating in a relationship.
ng
, Be
ha m
eet
• There are two types of Participation:yap
V id
1. Total Participation h w a
V i s
ri t a
m
2. Partial Participation ©A
31
Total Participation
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
32
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
33
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
34
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Specialization and
Generalization:
pus
ru Cam
• Specialization and Generalization are fundamental al u
ng
, Be
concepts in database modeling that are useful for ham
eet
establishing superclass-subclass relationships.idya
p
a V
i shw
ta V
m ri
©A
• They are extended ER features
35
Specialization :
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
36
Specialization :
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
pus
ru Cam
al u
ng
, Be
ha m
eet
id yap
a V
i shw
V
r ita
© Am
Generalization
pus
• Generalization is a bottom-up approach in which multiple lower-level Cam entities are
combined to form a single higher-level entity. l uru
nga
Be
• Generalization is usually used to find common attributes
a m, among entities to form a
generalized entity. It can also be thought ofpeas eththe opposite of specialization.
id ya
• The following enhanced entity relationship
a V diagram expresses entities in a
i
hierarchical database to demonstrate shw generalization:
ta V
m ri
©A
38
Generalization :
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Cust:
Name
pus
Phone
C a m
uruAddress
l Credit
nga
Bottom –up
, Be Email
Approach
ha m cid
eet
ya p
Vid
wa Emp:
i sh Name
V
r ita Ph
© Am Address
Eid
Sal
Generalization
39
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
40
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
disjoint entities
Mobile
PAN No
No
Employee pus
Cam
The lower level entities
will not have any
l uru
instances overlapping.
nga
i.e., the instance can IS A , Be
belong to only one of ha m
eet
the lower entities
ya p
a Vid
An employee can either Full Time
i shw Part Time
be a part time
r aV
Employee
it Employee
employee or full time
© Am
employee No. of
Salary
Hours
Person pus
Cam
Name
l uru
nga
IS A , Be
The lower level entities
ha m
may have overlapping eet
instances. ya p
a Vid
A teacher may be doing i s
Teacherhw Student
t a V
her part time degree in
mri
the same university
© A
Salary Eno Credits Reg No
Earned
42
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru Exp
condition based entities
ENo Degree
43
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru Name
user defined entities
RegNo Sem
44
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
45
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Total Participation
Mobile
PAN No
No
r aV
Employee
it Employee
© Am
No. of
Salary
Hours
46
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Partial Participation
Mobile
PAN No
No
Person-30
Person Emp-10pu
s
Cam
All Entities from higher level
Cust-15
entity may not participate in any
l uru
of the lower level entities.
nga
IS A , Be
Ex: I may have details of all
ha m
people in a locality of a eet
departmental store. Some of ya p
whom may be customer of the a Vid
store, few may be employees of i s
Employeehw Customer
that store ta V
mri
© A
Order
Salary
No.
47
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Complete the diagram. Continue to connect the entities with lines, and adding diamonds to describe
each relationship until all relationships have been described. Each of your entities may not have any
relationships, some may have multiple relationships. That is okay.
48
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
pus
Cam ru
al u
ng
, Be
How to Draw a completeethER am Diagram?????
a pe
id y
a V
i shw
ta V
mri
©A
49
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
50
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
pus
ru Cam
al u
How do we identify Entities ????? ng
, Be
ha m
eet
ya p
Vid
wa
Noun Phrase Approach
Vi sh
rita
m
©A
51
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Case Study 1:
In a University, there are multiple departments each of which is headed by a
pus
staff. There are multiple staffs employed in each department. There are various
m
Ca
l uru
courses offered by the department taught by teachers of the respective
nga
department. Students register for various courses.
, Be
ha m
(Assumption : Teachers teach only one course) eet
ya p
Vid
Draw the ERD wa
University (Ucode, Uname, location) i s
Xh
ta V
Department
m ri
Staff ©A
Teachers X
Course
Student
52
In a University, there are multiple departments each of which is headed by a staff.
i shw
ta V
r i
staff m A m o
1
Course
h © teaches
Students register for various courses. (Assumption : Teachers teach only one course)
m n
stud o
registers Course
53
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Dname
Dept Ccode
Dloc
course pus
Cnameam
u C
al ur
eng
, B Credit
ha m
eet
id yap
a V
Fname
i shw Name
Name
ta V
mri
Lname Stud
Staff
Sid © A RegNo
Ph No
Ph No
Age DoB
54
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Credit Ph No
grade DoB
Age
55
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
56
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
• Partial Keys are set of attributes with the help of which the tuples/records of the weak entities can
A1 B1
Strong Identifying Weak ---
Entity Relationship Entity B2 pus
A2
ru Cam
al u
eng B3
, B
ha m
eet
ya p
• Partial Key in the weak Entity is discriminator. V id
w a
• i sh is Strong Entity / Owner Entity.
Entity on which weak Entity is dependent
ta V on
r i
• To uniquely identify records in A m
a weak Entity:
©
Primary Key of the Owner Entity + Discriminator of the Weak Entity.
• Relationship between Weak Entity and Owner Entity is Identifying Relationship.
58
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
CampusCode RollNo
Relatio --- --
Campus
ship
nship
Has Stud
Name pus
Cam
CampusLoc ship
l uru
nga Sem
Roll No Name Sem , Be
CampusCode ha m
CampusLoc
01 A 5
eet
02 A 3 CBR
ya p Ettimadai
BLa V
id Bengaluru
01 B 5
i shw
V
03 C 3
r ita
© Am
Primary Key of the strong entity: Campus Code
Discriminator : Roll No
To uniquely identifying record /row of a weak entity : (CampusCode, RollNo)
59
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
CampusCode SlNo
Relatio --- --
Campus
ship
nship
Has Stud
Name pus
Cam
CampusLoc ship
l uru
nga Sem
Sl No Name Sem , Be
CampusCode ha m
CampusLoc
01 Adi 5
eet
02 A 3 CBR
ya p Ettimadai
BLa V
id Bengaluru
01 Abhi 5
i shw
V
02 C 3
r ita
© Am
Discriminator
CBR01 (campuscode,Slno)
BLR01
60
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru In a city, there are multiple univ, each of which has multiple library
• Assume in a (Amrita) University, there are multiple libraries and each library has
many student members. A student may be a member in multiple libraries.
pus
• Each library has its own set of books. Within the library, these books aare
C m identified by
a unique number. l uru
nga
• Students can borrow multiple books from subscribed library. , Be
ha m
• Students can also borrow books through inter ee t
library loan ie., in case the book is
ya p
unavailable in his/her subscribed library, i d
V the subscribed library avails from the other
wa
i sh
a V
library in which the student is not a member.
r it
Draw the ERD A m
©
Strong Entity BRANCH Weak Entity PK? Discriminator?
Strong Entity GENRE Weak Entity ? PK? Discriminator?
Strong Entity LIBRARY Weak Entity BOOK PK LibCode Discriminator BookNo
61
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Library : LibCode,LibLoc
L1, GndFlr
pus
L2 , FirstFlr
ru Cam
al u
ng
Book: Bno, Title
, Be
ha m
B1, DB eet
id yap
B2, OS a V
i shw
V
B1, PR r ita
© Am
B2, OS
63
Loans
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
book
from
1 m L1: B1, B2, B3, B4 Srini(B5)
LibNo
Library
LibLoc
L2: B1, B2, B5 ---sree(B3), raj(B4)
pus
ru Cam
al u
1 1 n g m
, Be
loans ha m Is a
has eet member
ya p
1 Vid n
bNo m wa
i sh
--- V Name
r ita
bname
Book
© Amm borrows Stud
RegNo
1
AuthorName
Ph No
64
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
65
Sreevidya B., Department of CSE, Amrita School of Engineering, Bengaluru
Case Study 4:
• Given below are entities, connect them appropriately with necessary
pus
relationship and relationship constraints including mapping cardinalities
C am and
l uru
participation constraints.
n ga
, Be
Complete the ERD with Attributes for each entity and key
m attributes if any.
tha
pee
d ya
Vi
a
i shw
ta V
mri
©A
66