Академический Документы
Профессиональный Документы
Культура Документы
CHAPTER 2
ENTITY-RELATIONSHIP MODELING
The Entity Relationship Model (ER Model) models the real world situations as a
collection of entities and relationships amongst the entities.
Entity Set An Entity-Set refers to a collection of entities of the same kind. Each
entity in an Entity-Set will have the same set of attributes and the set of attributes will
distinguish it from other Entity Sets. No other entity set will have exactly the same set of
attributes. Some of the attributes of an entity set may overlap with other entity sets.
Domain of an Attribute
Each attribute has a set of permitted values called its domain or value set, like the
attribute ‘NAME’ may have a domain that is set strings of characters of specified
maximum length.
P S Gill
2
Attribute Types:-
(b) If value is applicable, but not specified; like TEL#- an employee may not
be owning a Telephone.
(c) If value is applicable and specified but not known to the agency entering
the information; like an employee may be owning a Telephone but the
number may not be known to the organization.
Null value can only be assigned to an Attribute, if assigning value to that attribute
is optional (not mandatory). The Mandatory attributes cannot be assigned a
“Null” value.
P S Gill
3
RELATIONSHIP constraints
- Mapping Cardinalities
- Participation Constraint
Mapping Cardinalities. For a binary relationship set R between entity sets A and B,
the mapping cardinalities can be on of the following:-
R
A B
P S Gill
4
R
A B
R
A B
R
A B
Example:-
DEPOSITOR
CUSTOMER ACCOUNT
(One-to-One Relationship)
DEPOSITOR
CUSTOMER ACCOUNT
(One-to-Many Relationship)
DEPOSITOR
CUSTOMER ACCOUNT
P S Gill
5
(Many-to-One Relationship)
DEPOSITOR
CUSTOMER ACCOUNT
(Many-to-Many Relationship)
- Total Participation
- Partial Participation
Total Participation
An Entity Set E is said to have total participation in relationship set R if each entity in E
is participating at least in one relationship through R. In E-R Diagram, the Total
Participation is represented by a “Double Line” drawn between the Entity Set symbol and
the Relationship Set symbol.
Partial Participation
An Entity Set E is said to have partial participation in relationship set R if some of the
entities in E are not participating in any relationship through R. In E-R Diagram, the
Partial Participation is represented by a “Single Line” drawn between the Entity Set
symbol and the Relationship Set symbol.
P S Gill
6
Partial Participation
BORROWER
Total Participation
LOAN
Concept of Key
Super Key. A Super Key of an Entity Set or Relationship Set refers to the set of
attributes, which when taken collectively, will uniquely determine an entity within the
Entity Set or a Relationship within the Relationship Set. If K forms a Super Key (SK) of
an Entity Set E then any super set of K will also be a Super Key of E. So, a Super Key
may have some extraneous (unnecessary) attributes, which if removed, the balance set
may still form a Super Key of R.
Example :- Suppose each student in the Entity Set STUDENT (ROLL_NO, NAME,
BRANCH, FATHERS-NAME, ADDRESS, DOB, TEL-NO) has a unique value of
ROLL-NO. This implies that no two students can have same ROLL-NO. Then {ROLL-
NO, NAME} forms a super key of Entity-Set STUDENT. In this, the attribute NAME is
extraneous; which if removed, the balance set i.e. {ROLL-NO} still forms a Super Key of
STUDENT.
Candidate Key. A Super Key, whose no proper subset forms a Super Key, is called
a Candidate Key. Thus, Candidate Key is a minimal Super Key (i.e. a Super Key having
no extraneous attributes). An Entity Set may have more than one Candidate Keys.
Example:- The Entity Set STUDENT will have at least two Candidate Keys i.e.
{ROLL-NO} and {NAME, FATHERS-NAME, DOB, ADDRESS}.
Primary Key. Primary Key is one of the Candidate Keys that is designated by the
database designers as primary means of identifying entities within an entity set. In the E-
R Diagram, the Primary Key Attributes are underlined with a firm line.
Let R be a binary relationship set between Entity Sets E1 and E2. Let K1 and K2 be the
respective Primary Keys of E1 and E2. Then the Primary Key of Relationship Set R will
depend upon the cardinality mapping of the relationship set, as explained below:-
P S Gill
7
Example
CN AN
(i)
DEPOSITOR
CUSTOMER ACCOUNT
(One-to-One Relationship)
PK (DEPOSITOR) = CN or AN
CN AN
(ii)
DEPOSITOR
CUSTOMER ACCOUNT
(One-to-One Relationship)
CN AN
(iii)
DEPOSITOR
CUSTOMER ACCOUNT
P S Gill
8
(One-to-One Relationship)
CN AN
(iv)
DEPOSITOR
CUSTOMER ACCOUNT
(One-to-One Relationship)
An Entity Set is said to be a Weak Entity Set if it does not have sufficient attributes to
form its Primary Key. On the other hand, an entity set having a primary key of its own is
called a Strong Entity Set. A Weak Entity Set (say E 2) will be dependent for its existence
on a Strong Entity Set (say E 1) to form its Candidate Key. Then Entity Set E 2 is said to be
“Existence-Dependent” on E1 and E1 is said to be the “Owner Entity Set” of E 2. The
relationship R between E2 and E1 is called “Identifying Relationship”. The Weak Entity
Set E2 will have a set of attributes called its “Discriminator”, which together with the
Primary Key of E1 will form the Primary Key of E2.
E1
E2
P S Gill
9
EMPLOYEE DEPENDENT
- The Weak Entity Set DEPENDENT is Existence Dependent on the Strong Entity
Set EMPLOYEE.
Normally, a situation modeled by Weak Entity Set will have following features:-
(i)The Identifying Relationship will be one-to-many from Owner Entity Set to Weak
Entity Set.
(ii) The Participation of Owner Entity Set in the Identifying Relationship will be
partial and the participation of the Weak Entity Set in the Identifying Relationship
will be Total.
In the above example, the Weak Entity Set DEPENDENT can also be modeled as a multi-
valued attribute of Entity Set EMPLOYEE. The multi-valued attribute can be used to
indicate the names of the dependents of employees. But suppose we want to indicate
other parameters of dependents like dependent’s relationship with the employee then the
multi-valued approach will not be suitable. In this case, the Weak Entity approach will be
the ideal choice, since then the weak entity set DEPENDENT can have any number of
attributes.
A2 ISA C2
C1
A1 B1
En
E1 E2
In the above example, an Entity Set E has been specialized into Sub-groups designated as
E1 , E2 ….. En. E is called “Super Class” or “Higher Level Entity Set” and the entity sets E 1
, E2 ….. En are called “Sub Classes” or “Lower Level Entity Sets” of E. The common
attributes of all sub entity sets are represented with the super entity sets. And the distinct
attributes of each sub entity set are represented with the sub entity set.
The relationship of Higher Level Entity Set with its Lower Level Entity Sets is called ISA
relationship. It is read as “is a”.
Each Sub Class will inherit the Attributes of its Super Class; plus it will have its own
distinct Attributes. Like in the above case, each lower entity set will inherit attributes A 1
and A2 of the Super Class E.
Account- Balance
Number
ACCOUNT
Mat-Date
Int-Rate Installment
Interest-Rate ISA
P S Gill
11
RD
SAVINGS- Over-Draft
ACCOUNT Int-Rate
Mat-Date
CURRENT- FD
ACCOUNT
Specialization Constraints
Disjoint. It implies that an entity does not belong to more than one lower-
level entity set i.e. an account is either savings-account or current-account but not
both.
Total Each higher level entity must belong to a lower-level entity set.
Partial. Some higher-level entities may not belong to any lower-level entity set.
A1 A2 B1 B2
P S Gill
12
E1 R1 E2
Aggregated Higher Level Entity Set “R1”
R2
E3
C1 C2 C3
Here, the Relationship Set R1 between Entity Set E1 and Entity Set E2 has been
aggregated as Higher Level Entity Set “R1”. This Higher Level Entity Set is participating
in a Relationship R2 with Entity Set E3. Thus, through aggregation, we are able to
represent a Relationship between Relationship Set R1 and Entity Set E3.
If we represent this scenario without use of aggregation, then the E-R Diagram will be as
follows:-
BRANCH
EMPLOYEE
EBJ
JOB
EM BM
P S Gill
13
JM
MANAGER
The above Scenario can be better modeled by aggregating the Relationship Set “EBJ” a a
higher level Entity Set and the creating a relationship between this higher level entity set
and the Entity Set “MANAGER”, as indicated below:-
BRANCH
EMPLOYEE JOB
EBJ
EBJM
MANAGER
This modeling represents the situation more realistically, wherein the Relationship Set
“EBJM” indicates “which combinations of employee-branch-job” are being managed by
each manager.
P S Gill
14
(a) Tabular representation of a Strong Entity Set. A Strong Entity Set E will be
represented by a Table named “E”. The Table will have columns as follows:-
P S Gill
15
Let E be a Strong Entity Set with simple single-valued attributes a1,a2,……,an. This
Entity Set will be represented by a Table called E with n distinct columns, each of which
will correspond to one of the attributes. Let D1,D2,…Dn be the domains of attributes
a1,a2,….,an respectively. The Table E will comprise of a set of rows, which will be a
subset of the Cartesian Product D1 X D2 X…….Dn.
Example Age
DOB Tel_No
Name Cit
Univ_Roll_No
y
Stree
STUDENT H- t Pin
No
Addres
s
The derived attribute Age will not be represented in the STUDENT table. When required,
its value will be derived from DOB.
STUDENT
Univ_Roll_No Name DOB H-No Street City Pin
P S Gill
16
STUDENT-TEL-NO
Univ_Roll_No Tel_No
Example
C-
Account-No Branch-Name
Address
C-Id
Balance
C-Name
ACCOUNT
CUSTOMER DEPOSITOR
CUSTOMER
C-Id C-Name C-address
ACCOUNT
Account-Number Balance Branch-Name
P S Gill
17
DEPOSITOR
C-Id Account-Number Date-of-Operation
Example:-
Date-of-Operation
C- Account-No Branch-Name
Address
C-Id
Balance
C-Name
ACCOUNT
CUSTOMER DEPOSITOR
CUSTOMER
C-Id C-Name C-address
C-001 Ajay 320, Sector-26, Noida
P S Gill
18
ACCOUNT
Account-Number Balance Branch-Name
A-101 10000 Sec-18
A-203 30000 Sec-26
A-305 50000 CP
A-310 25000 RKP
DEPOSITOR
C-Id Account-Number Date-of-Operation
C-001 A-310 10-Jan-2007
C-220 A-101 23-Dec-2006
C-310 A-203 03-Feb-2007
C-505 A-305 27-Dec-2007
As obvious, the rows in DEPOSITOR table are having one-to-one mapping with the rows
in the CUSTOMER Table and also with the rows in the ACCOUNT Table. That is, the
first row of DEPOSITOR maps onto the fourth row of ACCOUNT, the second row of
DEPOSITOR maps onto the first row of ACCOUNT, the third row of DEPOSITOR maps
onto the second row of ACCOUNT and the last row of DEPOSITOR maps onto the third
row of ACCOUNT. Thus, the descriptive attribute Date-Of-Operation of the Relationship
Set DEPOSITOR can be shifted to either CUSTOMER or ACCOUNT. Also, the
DEPOSITOR Table can be combined either with the CUSTOMER Table or with the
ACCOUNT Table, without losing any information. The combined table will have union
of the columns of the two merged tables. Suppose, DEPOSITOR Table is merged with
the CUSTOMER Table, then the CUSTOMER Table will also include attributes
Account_Number and Date_Of_Operation . The resulting set of tables will then be:-
CUSTOMER
C-Id C-Name C-address Account- Date-of-
Number Operation
C-001 Ajay 320, Sector-26, Noida A-310 10-Jan-2007
C-220 Vijay 110,Sector-8, RKP A-101 23-Dec-2006
C-310 Ram 120,Sector-25, Noida A-203 03-Feb-2007
C-505 Shyam 303,Sector-22,RKP A-305 27-Dec-2007
ACCOUNT
Account-Number Balance Branch-Name
A-101 10000 Sec-18
A-203 30000 Sec-26
A-305 50000 CP
P S Gill
19
The combined CUSTOMER Table now includes the Primary Key (AN) of ACCOUNT
and descriptive attribute Date_Of_Operation of DEPOSITOR.
Date-of-Operation
Example
C-
Account-No Branch-Name
Address
C-Id
Balance
C-Name
ACCOUNT
CUSTOMER DEPOSITOR
CUSTOMER
C-Id C-Name C-address
C-001 Ajay 320, Sector-26, Noida
C-220 Vijay 110,Sector-8, RKP
C-310 Ram 120,Sector-25, Noida
C-505 Shyam 303,Sector-22,RKP
ACCOUNT
Account-Number Balance Branch-Name
A-101 10000 Sec-18
A-203 30000 Sec-26
A-305 50000 CP
A-310 25000 RKP
A-550 35000 CP
A-670 60000 Sec-18
DEPOSITOR
C-Id Account-Number Date-of-Operation
C-001 A-310 10-Jan-2007
C-220 A-101 23-Dec-2006
C-310 A-203 03-Feb-2007
C-505 A-305 27-Dec-2007
C-101 A-550 22-Dec-2006
P S Gill
20
The rows in the DEPOSITOR table have one-to-one mapping onto the rows in
ACCOUNT Table i.e. with the “Many-Side Entity Set” Table. That is, the first row of
DEPOSITOR maps onto the fourth row of ACCOUNT, the second row of DEPOSITOR
maps onto the first row of ACCOUNT, the third row of DEPOSITOR maps onto the
second row of ACCOUNT, the fourth row of DEPOSITOR maps onto the third row of
ACCOUNT, the fifth row of DEPOSITOR maps onto the fifth row of ACCOUNT and the
last row of DEPOSITOR maps onto the last row of ACCOUNT table. Thus, the
descriptive attribute Date-Of-Operation can be shifted to ACCOUNT (The “Many-Side”
Entity Set) and the DEPOSITOR Table can be with the ACCOUNT Table (i.e. with the
table of the “Many-Side” Entity Set), without losing any information. The resultant
ACCOUNT table will also include the Primary Key C-Id of CUSOMER table and
descriptive attribute DOO of the DEPOSITOR table. The resulting set of tables will then
be:-
CUSTOMER
C-Id C-Name C-address
C-001 Ajay 320, Sector-26, Noida
C-220 Vijay 110,Sector-8, RKP
C-310 Ram 120,Sector-25, Noida
C-505 Shyam 303,Sector-22,RKP
ACCOUNT
Account- Balance Branch-Name Customer_Id Date_of_Operation
Number
A-101 10000 Sec-18 C-220 23-Dec-2006
A-203 30000 Sec-26 C-310 03-Feb-2007
A-305 50000 CP C-505 27-Dec-2007
A-310 25000 RKP C-101 10-Jan-2007
A-550 35000 CP C-101 22-Dec-2006
A-670 60000 Sec-18 C-310 01-Jan-2007
Date-of-Operation
Example
C-
Account-No Branch-Name
Address
C-Id
Balance
C-Name
ACCOUNT
CUSTOMER
P S Gill
21
DEPOSITOR
CUSTOMER
C-Id C-Name C-address
C-001 Ajay 320, Sector-26, Noida
C-220 Vijay 110,Sector-8, RKP
C-310 Ram 120,Sector-25, Noida
C-505 Shyam 303,Sector-22, RKP
ACCOUNT
Account-Number Balance Branch-Name
A-101 10000 Sec-18
A-203 30000 Sec-26
DEPOSITOR
C-Id Account-Number Date-of-Operation
C-001 A-101 10-Jan-2007
C-220 A-203 23-Dec-2006
C-310 A-101 03-Feb-2007
C-505 A-203 27-Dec-2007
The rows in the DEPOSITOR table have one-to-one mapping onto the rows in
CUSTOMER Table i.e. with the “Many-Side Entity Set” Table. Thus, the descriptive
attributes of DEPOSITOR can be shifted to “Many-Side” Entity Set CUSTOMER and
the DEPOSITOR Table can be with the CUSTOMER Table, without losing any
information. The resultant CUSTOMER table will also include the Primary Key
Account_Number of ACCOUNT table and descriptive attribute DOO of the
DEPOSITOR table. The resulting set of tables will then be:-
CUSTOMER
C-Id C-Name C-address Account_Number DOO
C-001 Ajay 320, Sector-26, Noida A-101 10-Jan-2007
C-220 Vijay 110,Sector-8, RKP A-203 23-Dec-2006
C-310 Ram 120,Sector-25, Noida A-101 03-Feb-2007
C-505 Shyam 303,Sector-22, RKP A-203 27-Dec-2007
ACCOUNT
Account-Number Balance Branch-Name
A-101 10000 Sec-18
A-203 30000 Sec-26
P S Gill
22
combine then we have to combine with both the Entity Sets and that would add
unnecessary data redundancy, which is not acceptable.
Date-of-Operation
Example
C-
Account-No Branch-Name
Address
C-Id
Balance
C-Name
ACCOUNT
CUSTOMER DEPOSITOR
CUSTOMER
C-Id C-Name C-address
C-001 Ajay 320, Sector-26, Noida
C-220 Vijay 110,Sector-8, RKP
C-310 Ram 120,Sector-25, Noida
C-505 Shyam 303,Sector-22, RKP
ACCOUNT
Account-Number Balance Branch-Name
A-101 10000 Sec-18
A-203 30000 Sec-26
A-305 50000 CP
A-310 25000 RKP
DEPOSITOR
C-Id Account-Number Date-of-Operation
C-001 A-101 10-Jan-2007
C-220 A-203 23-Dec-2006
C-310 A-101 03-Feb-2007
C-505 A-203 27-Dec-2007
C-101 A-305 30-Dec-2007
C-505 A-310 02-Jan-2007
Now, the rows in the DEPOSITOR table do not have one-to-one mapping with
CUSTOMER table and also with the ACCOUNT table. So, the DEPOSITOR table can
neither be merged with CUSTOMER table nor with ACCOUNT table. Thus, there has to
be a separate table for DEPOSITOR as indicated above. Also, the descriptive attributes of
the Relationship Set cannot be shifted to the participating Entity Sets; the descriptive
attributes have to remain with the relationship set itself.
P S Gill
23
(c) Tabular representation of Weak Entity Sets. Let A be a Weak Entity Set
with descriptive Attributes a1,a2,……,am. Let B be the Strong Entity Set on which A is
existence dependent. Let the primary key of B consist of attributes b1,b2,….bn. The
Entity Set A is represented by a Table called A with (m+n) columns, each column
representing one of the attributes from the set {a1,a2,……am} U {b1,b2,….bn}.
Example: Payment-Date
Payment-
Amoun No
Loan-No t Installmen
t
LOAN- PAYMENT
LOAN PAYMENT
There will be Tables LOAN and PAYMENT; the PAYMENT table will also include the
Primary Key of Loan i.e. Loan-No. The Primary Key of table PAYMENT will be
{Loan-No, Payment-No} where the attribute Payment-No is called a “Discriminator” or
“Partial Key” of the table PAYMENT.
Create a Table each for the higher-level entity set and for each lower-level entity
set. The table for lower-level entity set will include its own attributes plus all the
Primary-Key attributes of its higher-level entity set.
Account- Balance
Number
ACCOUNT
Mat-Date
Int-Rate Installment
Interest-Rate ISA
RD
SAVINGS- Over-Draft
ACCOUNT Int-Rate
P S Gill
24
Mat-Date
CURRENT- FD
ACCOUNT
For example, in the above case there will five tables i.e. ACCOUNT, SAVINGS-
ACCOUNT, CURRENT-ACCOUNT, FD and RD. The table ACCOUNT will have
columns Account-Number and Balance; and table SAVINGS-ACCOUNT will have
columns Account-Number and Interest Rate; and table CURRENT-RATE will have
columns Account-Number and Over-Draft. Same is applicable to the tables FD and RD.
B-Name
E- B#
E# Name
BRANCH J#
EMPLOYEE JOB
EBJ
Mgr- EBJM
Id
MANAGER
P S Gill
25
In the above scenario, there will be tables for Entity Sets EMPLOYEE, BRANCH, JOB
and MANAGER. There will be one table for Relationship Set EBJM having Attributes
E#, B#, J# and Mgr-Id. No table is required for the Relationship Set EBJ because this
table would be a subset of table EBJM.
EBJM
E# B# J# Mgr-Id
AIRCRAFT
TO_PLACE
FLT_ CREW
CREW
C_DATE
CONFIRMED
CANCELLATION RESERVATION
SEAT_NO
TICKET_N
O ISSUE_DATE
AMOUNT
VOUCHER
_NO
FARE
P S Gill
26
TICKET
REFUND
P_ADDRES
S
P_TEL_NO
P_NAME
PASSENGER
The above E-R Diagram can be reduced to the following set of tables:-
The SEAT_NO will get defined only after a passenger checks in for a flight.
P S Gill
27
O_ADDRESS
O_TEL_NO
O-NAME
OWNER
PREMIUM
COLOR EXPIRY_DATE
MODEL
REG_NO
BONUS
POLICY_NO
MAKE
VEHICLE INSURANCE_POLICY
P_DAT
A_DATE E
A_REPORT_NO PAYMENT_
VOUCHER P_AMOUN
_NO T
PLACE
ACCIDENT CLAIM_PAYMENT
S_REPORT_NO
ASSESSED
_DAMAGE
SURVEYOR REPORT
REPAIR_ITEM
COST
P S Gill
28
REF_NO
REPAIRS
Exercises
Ex.2.3 Explain the concept of Super Keys, Candidate Keys and Primary Keys of
an Entity Set. Explain the determination of Primary Key of a binary Relationship set.
How is it influenced by the Cardinality Mapping of the Entity Sets participating in the
Relationship Set?
Ex.2.4 Explain the concept Weak Entity Sets and Identifying Relationships.
Explain how a multi-valued attribute can be better modeled as a Weak Entity Set.
Ex.2.5 Explain the concepts of Specialization and Generalization. What are the
different types constraints involved in specialization? Distinguish between Total & Partial
Specialization and between Disjoint & Overlapping Specialization.
Ex.2.7 Draw E-R diagrams to indicate the following relationships between entity set
Operator and entity set Machine:-
(a) Each Machine can be operated by many Operators but each Operator can
operate only one machine.
(b) An operator can operate many machine and each machine can be operated
by many Operators.
Ex.2.7 Make E-R Diagrams for the following real-world situations (Indicate clearly
entity sets, relationship sets, cardinalities, attributes and candidate Keys. Also indicate
P S Gill
29
any weak entity sets, specialization, generalization and aggregation etc.) Also reduce the
E-R diagrams to Tables:-
P S Gill