Professional Documents
Culture Documents
Chapter 2 ENTITY RELATIONSHIP MODEL
Chapter 2 ENTITY RELATIONSHIP MODEL
Key points :
Entity, types of attributes, relationship set, keys, domain, null, weak entity set,
cardinality, degree, specialization, generalization, aggregation,
2.1 INTRODUCTION
Data model is used to describe data, data relationship and constraints on data. A number
of different data models have proposed. They can broadly be classified into two
categories:
Object-based logical models.
Record-based logical models.
The object-based model can be defined as a collection of conceptual tools for describing
data, data relationships, and data constraints. The record-based model describes the data
structures and access techniques of a DBMS. There are various different object-based
models. Some of the more popular ones are:
The entity-relationship model
The binary model
The infological model
The semantic model
Of these, the most widely used one is the Entity-Relationship Model. It has gained
acceptance as the ideal data model for database design. This model was introduced by
Peter Chen in 1976, and since then it has been reformed by several persons. The entity –
relationship model (E R Model) is based on a perception of real world that is made up
of a collection objects or entities and the relationship among these.
Conceptual Model
Before going to explaining the entity-relationship model, we will briefly discuss
database design. Database design involves designing the conceptual design model of the
database. The conceptual model reflects the entities and their relationships, based on the
data processing needs of the organization. This can be considered equivalent to the
conceptual level.
The conceptual model is a communication tool between the various users of the data. It
is developed without any concern for physical representation. The conceptual model is
used to organize, visualize, plan and communicate ideas. It is independent of the
database management system. Before actually implementing the database, the
conceptual model is designed. At this stage, requirements of all the users are considered
to decide upon the actual data to be stored in the system. This conceptual model is then
mapped to the DBMS that is actually to be used.
Data analysis is the first step in designing a conceptual model. Data analysis begins
with collecting information about the data. This usually involves using a questionnaire
or a similar method to obtain a list of data that the organization needs. Existing forms,
bills, reports are starting points for data collection. The data analysis involves
identifying entities, their attributes, and the relationships between attributes. The E-R
Model is a way to form and represent the conceptual model of database design
1) ENTITIES
2) ATTRIBUTES
3) RELATIONSHIPS
2.2.1 Entity :
Entities are the people, places, things, events and concepts of interest to an
organisation. In short, anything which an organisation needs to store data about. Entity
can be concrete like employee, book, project, publisher etc. and can be abstract or a
concept for example title, job, company etc. which have no physical existence. Entity
set represents collection of things. For example, an EMPLOYEE entity set might
represent a collection of all the employees that work for an organisation. Individual
members (employees) of the collection are called instance of the EMPLOYEE entity
set.
2.2.2 Attribute:
Properties or characteristics possessed by an entity are called as attributes. Attributes
are same for each entity set but their values may differ from each other. For example,
EMPLOYEE entity set has attributes name, age, empid and salary but the values of
these attributes may be different for each employee in the entity set.
2.2.2.1 Domain
The set of possible values for an attribute is called the domain of the attribute.
Example:
– The domain of attribute marital status is just the four values: single,
married, divorced, widowed.
– The domain of the attribute month is the twelve values ranging from January
to December.
- The domain of attribute empid of EMPLOYEE entity set consist of only positive
integers.
2.2.2.2 Key attribute
The attribute (or combination of attributes) that is unique for every entity instance
– E.g the account number of an account, the employee id of an employee etc.
2.2.2.3 Simple Vs composite attribute
Simple attribute: An attribute that cannot be divided into simpler components is called
simple attribute. E.g age of an employee, pub-id of a book title of a book entity.
Composite attribute: An attribute that can be split into components is called composite
attrbute. E.g Date of joining of the employee can be split into day, month and year
2.2.5 Keys
A key is a single attributer or a combination of attributes whose values uniquely identify each
tuple in that relation. In other words, no tow entities in an entity set are allowed to have exactly
the same value for all attributes. A key allows us to identify a set of attributes that are suffice to
distinguish relationships from each others.
2.2.5.1 Superkey
An attribute, or group of attributes, that is sufficient to distinguish every tuple in the
relation from every other one. Each super key is called a candidate key
2.2.6 Relationship
A relationship type between two entity types defines the set of all associations between
these entity types. Each instance of the relationship between members of these entity
types is called a relationship instance. For example:
EMPLOYEEs work in a DEPARTMENT
LAWYERs advise CLIENTs
EQUIPMENT is allocated to PROJECTs
TRUCK is a type of VEHICLE
P1 C1
P2C2
P3 C3
P4 C4
PERSON CHAIR
Figure 2.3 One to One: One instance of entity type Person is related to one instance of
the entity type Chair.
E1
O1
E2
O2 E3
E4
O3
E5
ORGANIZATION EMPLOYEE
Figure 2.4 One to Many: One instance of entity type Organization is related to
multiple instances of entity type Employee
E1 D1
E2
D2
E3
E4 D3
E5
EMPLOYEE DEPARTMENT
Figure 2.5 Many to one: Multiple instance of employees is related to one instance of
department
S1 C1
S2 C2
S3 C3
S4 C4
STUDENT COURSE
Figure 2.6 Many to many: Multiple instances of Student are related to multiple
instances of Course Entity.
2.2.6.4 Existence
Existence denotes whether the existence of an entity instance is dependent upon the
existence of another, related, entity instance. The existence of an entity in a relationship
is defined as either mandatory or optional.
Mandatory :If an instance of an entity must always occur for an entity to be included
in a relationship, then it is mandatory. An example of mandatory existence is the
statement "every project must be managed by a single department".
Optional : If the instance of the entity is not required, it is optional. An example of
optional existence is the statement, "employees may be assigned to work on
projects".
Floor
Composite Attribute Street
Building
Address
DOB
Derived
attribute
Age
Name
Employee Skills
E#
A relationship is represented as a diamond between two entity types. It has a label that
explains the relationship. Usually the convention is to read the ER diagram from top to
bottom and from left to right. So, the relationship name is so chosen as to make sense
when read from left to right. The relationship above is read as student enrolls-in course
Employee Manages
Head of
Employee Department
Partial :All instances of the entity type Employee don’t participate in the relationship,
Head-of. Every employee doesn’t head a department. So, employee entity type is said to
partially participate in the relationship.
Total : But, every department would be headed by some employee. So, all instances of
the entity type Department participate in this relationship. So, we say that it is total
participation from the department side.
2.4.2.5 Attribute of a relationship: These attributes best describe the
relationship rather than any individual entity
Medicine
No. of Days
Dosage
2.4.2.6 Weak Entity: Entity that depends on other entity for its existence and doesn’t
have key attribute of its own is called Weak Entity.
The dependant entity is represented by a double lined rectangle and the identifying
relationship by a double lined diamond . the identifying relationship is the one which
relates the weak entity with the strong entity on which it depends.
An entity may be associated with one, none, or many occurrences of another entity. In
ER diagrams, the types of relationships are represented as follows;
Figure 2. 15: Cardinality
A R B
A R B
A R B
A R B
2.5.1 Superclass and Subclass: Certain instances of an entity class can include
attributes that are not needed in other instances of the same entity class. In these cases,
it is useful to use a superclass/subclass structure. This structure is also called a
generalization/ specialization hierarchy.
i) Subclass: A subgroup an entity type which has attributes that are distinct from those
in other subgroups
ii) Superclass: An generic entity type that has a relationship with one or
more subclasses
iii)Inheritance
Subclass entities inherit values of all attributes of the superclass
An instance of a subclass is also an instance of the superclass
SECERATRY
ENGINEER
TEHCNICIAN
Each of these employee types is described by a set of attributes that includes all the
attributes of entity set employee plus possibly additional attributes. For example,
SECERATRY entities my be described further by the attribute TypingSpeed, whereas
TECHNICIAN entities may be described further by the attribute Tgrade and
ENGINEER entities may be described by EngType. The processof designating
subgroupings within an entity set is called specialization. The specialization of
EMPLOYEE allow us to
distinguish among EMPLOYEES according to whether they are SECERATRY,
TECHNICIAN or ENGINEER.
We call each of these subgrouping a subclass of the EMPLOYEE entity type, and the
EMPLOYEE entity type is called the superclass for each of these subclasses. In terms
of E-R diagram, specialization is depicted by a triangle component labeled ISA. The
label ISA stands for “is a” and represents, for example, that a customer “is a” person.
The ISA relationship can also be referred as superclass-subclass relationship.
NoOfPassengers
Price
MaxSpeed CAR
VehicleId
LicencePlacte No.
NoOfAxles
Price
Tonnage
TRUCK VehicleId
LicencePlacte No.
Figure 2. 20 (a)
Price
VehicleId
LicencePlacteNo
VEHICLE
ISA
MaxSpeed
NoOfPasseng Tonnage
NoOfAxle
CAR
TRUCK
Figure 2. 20(b)
Employeei Address
Name
JobType
EMPLOYEE
ISA
TypingSpee EngType
TGrade
SECRETARY ENGINEER
TECHNICIAN
Figure 2. 21: Condition defined constraint
Disjoint: In a disjoint hierarchy, an entity instance can be in only one subtype. For
example, the entity EMPLOYEE, may have two subtypes, CLASSIFIED and WAGES.
An employee may be one type or the other but not both. Figure 2. 22 (a) shows disjoint
and Figure 2. 22 (b) overlapping generalization hierarchy
EMPLOYEE
ISA
CLASSIFIED WAGES
Overlapping in lower-level entity set is the default case. We can denote disjointedness
constraint in an E-R diagram by adding the word disjoint next to the triangle symbol.
PERSON
ISA
ISA
HOURLY_EMPLOYEE SALARIED_EMPLOYEE
2.5.5 AGGREGATION
The E-R model has one limitation that it is not possible to express relationships among
relationships. In such situations we use aggregation. Aggregation, is an approach of
modeling a relationship set as a higher level entity set or, in other words, aggregation
helps to model the participation of one relationship set into other relationship set. For
example, consider ‘PUBLISHER’ database in which an author writes a particular book
and a publisher publishes the book on a specific date written by a particular author. To
model the situation, an E-R diagram is shown in fig. 2.25.
Assumptions :
• A college contains many departments
• Each department can offer any number of courses
• Many instructors can work in a department
• An instructor can work only in one department
• For each department there is a Head
• An instructor can be head of only one department
• Each instructor can take any number of courses
• A course can be taken by only one instructor
• A student can enroll for any number of courses
• Each course can have any number of students
Figure 2.27
Building
Years of Service
Name
Employee
Skillset
E#
Here dependant is a weak entity. Dependant doesn’t mean anything to the problem
without the information on for which employee the person is a dependant.
Employee(E#, Name.................)
Case 2: Uniform participation type: If both the entities take uniform participation in the
Binary (1:1) relationship the primary key of either of the participants can become a
foreign key in the other.
Figrure 2.34 Binary (1:1) Uniform participation
2.7.4Converting specialization
Generalization is concept of representing entity sets in the form of hierarchy. Higher
level entity set is represented by table containing attribute common to lower level entity
set. Lower level entity set is represented by table containing column as primary key of
higher level entity set and a specialized attribute corresponding to that lower level entity
set.
E# Ename
DOB Address
EMPLOYEE
ISA
BasicSal
NoOfHrs
HOURLY_EMPLOYEE SALARIED_EMPLOYEE
Figure 2.48 Specialization
EMPLOYEE HOURL_EMPLOYEE
E# PK E# PK
Ename NoOfHrs
DOB
Address SALARAIED_EMPLOYEE
E# PK
BasicSal
Figure 2.49 Conversion of specialization to table
Participating entities: The entities which are joined by the relation. In a Many to Many
relationship, it is necessary to create separate tables for participating entities and
relationships. In the banking application we have Customer and Loan Entities have a
Many to Many relationship. Hence one should create separate tables for
CUSTOMER
LOANS
LOAN_DETAILS.
SUMMARY
E-R Model is a conceptual data model used in mapping requirements of initial phase
into database design.
Conceptual model reflects the entities and their relationships, based on the data
processing needs of the organization
Entities are the people, places, things, events and concepts of interest to an organization
Properties or characteristics possessed by an entity are called as attributes
The set of possible values for an attribute is called the domain of the attribute
The attribute (or combination of attributes) that is unique for every entity instance is
called key attribute.
Entity that depends on other entity for its existence and doesn’t have key
attribute of its own is called Weak Entity Set.
Attributes that can take many values for each entity instance are called multi-valued
attributes
Null value of an attribute is considered if that attribute does not have a value for a
particular entity
A Primary key uniquely identifies an entity in entity set. Keys that are eligible to
become primary key are called candidate Keys and the superset of candidate key is
called superkey.
A foreign key is a set of attribute(s) whose values are required to match values of a
candidate key in the same or another table
Relationship is the association between entities.
The degree of a relationship is the number of entities associated with the relationship.
Descriptive attribute is an attribute of a relationship exists between different entity
sets.
Mapping constraint specifies the association of entities in an entity set with other
entity set.
Participation constraint imposes constraints on participation of entities in the
specified relationship.
Specialization is the process of defining a set of subclasses of an entity type. It is a top
down approach.
Generalization is a reverse process of abstraction, which suppresses the differences
among several entity types. It is a bottom up approach.
Aggregation is an abstract concept for building composite objects from their
components.
REVIEW QUESTIONS
Q.1 Explain following with appropriate example:
(i) Entity set
(ii) Key constraints
(iii) Participation constraints
(iv) Class hierarchy
(v) Aggregation
(vi) Weak entity set
Q.2. Draw an E-R diagram that captures following information related to airport:
(i) Every airplane has a registration number and each airplane is of specific model.
(ii) The airport accommodates a number of airplane models, and each model is
identified by a model number and has a capacity and weight.
(iii) A number of technicians work at airport who have eid, name, address, phone
number and salary of each technician. Each technician is an expert of one or
more plane models.
(iv) The airport has a number of tests that are used periodically to ensure that
airplanes are still worth. Each test has test number, a name and maximum
possible score.
Q.3. Any weak entity set can be converted to strong entity set by simply adding appropriate
attribute. Why, then, do we have weak entity sets?
Q.4. Discuss the naming conventions and symbols used in E-R diagram?
Q.5. Design a generalization specialization hierarchy for a motor vehicle sales company.
The company sell Motorcycles, Cars, Vans and Buses. Justify the placement of attribute
at each level of hierarchy. Explain why they should not be placed at higher or lower
level?
Q.6. Design an E-R diagram that capture the following information about publisher-house
(i) Every publisher has a publisher-id, name, mainoffice, phone number.
(ii) Book have book-id, bname, subject, price and edition number.
(iii) Author has author-id, name, specialized area, qualification.
(iv) A publisher can publish many books. Similarly a book is published by only a
single publisher. Joint venture of publisher is restricted.
(v) A publisher can hire the author to write the book or gave a job to the author.
Author write many books not restricted to a single publisher.
(vi) Royalty given to each author is also recorded with the accordance of publisher.
Q.7 In a university database, information on the following is to be
kept.
[Raj. Univ., 1998]
Faculty (name, dept, title, office, ext, email)
Staff (name, dept, job, ext, email)
Graduate (id, name, address, prev-degree, enrolled program)
Undergraduate (id, name, address, year, major) Teaching—
Assistant (id, name, quarter, course)
Course (id, title, day, hour, room)
Reader (id, name, quarter, course, hour)
Review-section (course-id, TA, day, hour, room)
The following constraints apply:
Professors have a teaching assistant (TA) for each course they teach, TA must be a
graduate student. TA’s hold review section for some course several reader can be
assigned to one course or review section. All students, TA and reader attend the course.
Develop an E-R diagram for above specification.
Q.8 With the help of suitable example explain:
(i) Key constraints. [Raj. Univ., 1998, 2005]
(ii) Strong and weak entity set [Raj. Univ., 1998, 2005]
(iii) Participation constraints [Raj. Univ., 2003]
(iv) Class Hierarchies [Raj. Univ., 2003]
(v) Aggregation [Raj. Univ., 2003, 2005]
(vi) Distributed database [Raj. Univ., 2005]
(vii) Cardinality [Raj. Univ., 2005]
(viii) Candidate key [Raj. Univ., 2005]
Q.9 A software company manages a number of software projects. The company is
organized into many departments. Each department has unique id, name and manager.
The company has many employees. The company keeps track of id-number, name birth
date, address, joining date, leaving date, salary and department. An employee can be
assigned many software projects. Each project has unique id, name and machine. A
project may be jointly executed by more than one department. But all employee of a
given department may not be assigned to projects handled by the department. Each
project has a project
leader. Similarly projects are supervised by a group leader. Some of departments are
non technical. Draw an E-R diagram for above description. [Raj. Univ., 1999]
Q.10 A database is being constructed to keep track of teams and games of sports league. A
team has number of players, not all of whom participates in each game. It is desire to
keep track of all players participating in each game for each team, the position they
played in that game, and result of game. Design an E-R diagram. [Raj. Univ., 2002]
Q.11 Create an E-R diagram for each of following:
(i) Each company operates four departments and each department belong to one
company.
(ii) Each department employs one or more employee and each employee works for
one department.
(iii) Each of employees in part (ii) may or may not have one or more dependents
and each dependent belongs to employee.
(iv) Represent all E-R diagrams described in (i) (ii) and (iii) as single E-R
diagram.
[Raj. Univ., 2004]
Q.12 What is the role of E-R model in Database design? Draw an E-R diagram for bank
management system. [Raj. Univ., 2005]