You are on page 1of 15

The Entity-Relationship Model.

This lecture video presents a top-down approach to data model


which is the Entity-Relationship Model and the conversion of the
ER model to the relational model.

After completing this chapter, you should be familiar with the


following concepts:
 Entity, Attribute, and Relationship
 Entity classification – Strong entity, Weak entity, and
Associative entity
 Attribute classification – Single value, Multivalue,
Derived, and Null attribute.
 Relationship classification – one-to-one, one-to-many, many-
to-many relationship
 Mapping ER model to relation model 

What is the Entity-Relationship Model?


Entity-Relationship (ER) model gives the conceptual model of the
world to be represented in the database.

ER Model is based on an awareness of a real-world that consists


of a collection of basic
objects called entities and relationships among these objects.
If you want to represent the database schema in the ER model
pictorially, you can use the Entity-Relationship diagram.

What is the Entity-Relationship diagram?


ER diagram is a graphical modeling tool to standardize ER
modeling used in representing database schema. The basic building
blocks of the entity-relationship diagram are Entity, Attribute,
and Relationship.

Entity - An entity is an object that exists and


is distinguishable from other objects. In other words, the entity
can be uniquely identified.
The examples of entities are:
o An entity Person, for example, Dr. Rolyn C. Daguil.
o An entity Department, for example, the College of
Computer and Information Sciences
o An entity City, for example, Butuan City,
Entity Type - An entity type is a collection of similar entities.
Some examples of entity types are:
o All faculty in the College of Computer and Information
Sciences, the entity type is Faculty.
o All students in Caraga State University, the entity
type is Student.
o If you have entities like star, square, triangle, and
rectangle. This can be a group of shapes. So the entity
is shape.
There are some cases that an entity may belong to more than
one entity type. 
For example, a person working in a particular department can
pursue higher education as part-time. Hence the same person
is an INSTRUCTOR at one instance and STUDENT at another
instance.
Attributes - Attributes are properties of entity types. In other
words, entities are described in a database by a set of
attributes.
The following are an example of attributes:
o Brand, cost, and weight are the attributes of the
entity CELLPHONE.
o ID number, name, and program are the attributes of the
entity STUDENT.
Relationship - A relationship is an association of entities where
the association includes one entity from each participating
entity type whereas relationship type is a meaningful association
between entity types.
The examples of relationship types are:
o Teaches is the relationship type between LECTURER and
STUDENT.
o Buying is the relationship between VENDOR and CUSTOMER.
o Treatment is the relationship between DOCTOR and
PATIENT.
ER Diagram symbols
In the ER diagram:
 A rectangle represents an entity set.
 An ellipse represents an attribute.
 A diamond represents a relationship.
 Lines represent linking of attributes to entity sets and
entity sets to
relationship sets.

Example of an ER diagram

Let us consider this simple ER diagram.


In the ER diagram, the two entities are STUDENT and CLASS. Two
simple attributes which are associated with the entity STUDENT
are Roll number and the name. While the two simple attributes
associated with the entity CLASS are Subject Name and Hall
Number. The relationship between the two entities STUDENT and
CLASS is Attends,

Classification of Entity Sets


Entity sets can be broadly classified into:
 Strong entity - is one whose existence does not depend on
other entity.
 Weak entity - is one whose existence depends on other
entity. 
 Associative entity – is one whose existence depends on two
or more other entities. This type of entity has many-many
relationships.

Consider the example, a student takes a course. Here the student


is a strong entity while the course is a weak entity.

In this example, the course is considered a weak entity because,


if there are no students to take a particular course, then that
course cannot be offered. The COURSE entity depends on the
STUDENT entity.

Example of an associative entity. Here the student and class are


both strong entity while the enrollment is an associative entity.
The existence of enrollment entity depends on the two entity, the
student and class entity.

Attribute Classification
The attribute is used to describe the properties of the entity.
This attribute can be broadly classified based on value and
structure.
Based on value the attribute can be classified into a single
value, multivalue, derived, and null value attribute while Based
on structure, the attribute can be classified as a simple and
composite attribute.

Symbols Used in the ER Diagram

 Single Value Attribute - there is only one value associated


with that attribute. The examples of single value attribute
are the age of a student, the ID number.
  Multivalued Attribute - In the case of the multivalue
attribute, more than one value will be associated with that
attribute. The examples of a multivalued attribute are
skills and talents.
 Derived Attribute - A derived attribute is
an attribute whose value is calculated (derived) from
other attributes. The derived attribute need not be
physically stored within the database; instead, it can
be derived by using some calculation. The example is the age
of an employee can be derived from the date of birth that
stored in the database. Also, the experience of an employee
in an organization can be derived from the date of joining
of the employee.

 Null Value Attribute - In some cases, a particular entity


may not have any applicable value for an attribute. For such
a situation, a special value called null value is created.
For example, in application forms, there is one column
called phone no. if a person does not have a phone then a
null value is stored in the database.
 Composite Attribute - Composite attribute is one which can
be further subdivided into simple attributes. For example,
consider the attribute “address” which can be further
subdivided into Street name, City, and State.
Relationship Classification
A relationship is an association among one or more entities. This
relationship can be broadly classified into one-to-one relation,
one-to-many relation, many-to-many relation and recursive
relation.

 One-to-Many Relationship Type - Example of a one-to-many


relationship is Department having more than one employees. 
 One-to-One Relationship Type – Example the relationship
between the President and the country is an example of a
one-to-one relationship. For a particular country, there
will be only one President.  
 Many-to-Many Relationship Type – Example the relationship
between EMPLOYEE entity and PROJECT entity is an example of
a many-to-many relationship. Many employees will be working
in many projects hence the relationship between employee and
project is a many-to-many relationship.
The symbols used in relationship types
Mapping Regular Entities 
Regular entities are entities that have an independent existence
and generally represent real-world objects such as persons and
products. Regular entities are represented by rectangles with a
single line.
The steps in mapping Regular entities to table:
 The name of the relation is generally the same as the entity
type.
Entity name = Name of the relation or table
 Each simple attribute of the entity type becomes a column of
the relation.
Attributes of ER diagram=Column name of the table
 The identifier or the unique attribute of the entity type
becomes the primary key of the corresponding relation.

     STUDENT
ID number (PK) Name Program
101-00001 Roger Federer BSIT
101-00002 Roaddict Oco BSCS
101-00003 Akio Mico BSIS

In our example, the entity name is STUDENT which is also the


name of the relation. The attributes of STUDENT entity are
ID number, name, and program which forms the column of the
relation.

Mapping Composite Attribute in an ER Diagram to Tables


In this example, we have a CUSTOMER entity which has 3
attributes. The 3 attributes are customer id, customer name and
customer address. Both customer id and name are simple attributes
while the customer address is a composite attribute. 
So, when an entity type has a composite attribute, only the
simple component attributes of the composite attribute are
included in the relation.

Mapping Multivalued Attributes in ER Diagram to Tables

A multivalued attribute is having more than one value. One way to


map a multivalued attribute is to create another tables.
In this example, the skill associated with the CUSTOMER is a
multivalued attribute, since a CUSTOMER can have more than one
skill as driving, electrician, welder, etc.
The first relation contains all of the attributes of the entity
type except the multivalued attribute.

The second relation contains two attributes. The first attribute


is the primary key from the CUSTOMER relation, which becomes a
foreign key in the CUSTOMER_SKILL relation. The second attribute
is the multivalued attribute.

So, this is the final corresponding table:

Mapping “Weak Entities” in the ER Diagram to Tables


Since the weak entities are dependent, you need first to create
the relation of the strong entities. Then, follow the weak
entities.
In this example, we have two entities which are EMPLOYEE and
DEPENDENT. But the DEPENDENT is a weak entity while EMPLOYEE is a
strong entity. So, the first step is to create a relation of the
strong entity.

Then the second step is to create a relation of the weak entity.

The last step is for each weak entity type, include the primary
key of the identifying relation as a foreign key attribute. The
identifying relation of DEPENDENT is the EMPLOYEE relation and
the primary key is Employee_ID. So we add one additional
attribute to the DEPENDENT relation which is Employee_ID. As a
good practice, the foreign key attribute name is the same name as
the referred primary key.

So, this is the final corresponding table: This type of ERD can
be also classified as a one-to-many relationship.
Mapping Associative Entity to Tables
The many-to-many relationship can be modelled as an associative
entity in the ER diagram.
For example, we have 3 entities, the customer, shipment and
vendor. Both customer and vendor are strong entities while the
shipment is an associative entity. The existence of shipment
depends on the customer and the vendor.

The first step to do is create a relation of all the strong


entities.
The second step is the weak entity.

The last step is for each weak entity type, include the primary
key of the identifying relation as a foreign key attribute. The
identifying relations of SHIPMENT are CUSTOMER relation and
VENDOR relation. The primary key of CUSTOMER relation is the
Customer-ID while the primary key of VENDOR relation is the
Vendor-ID. So we add two additional attributes to the SHIPMENT
relation which are Customer-ID and Vendor-ID. As a good practice,
the foreign key attribute name is the same name as the referred
primary key.
The corresponding table is given by:
As a good practice, each relation should be assigned an
identifier (An additional attribute) to identify uniquely the
rows. This identifier is the primary key of the relation.

Assignment:
Given the BioData Form, draw the following:
1. Entity-Relationship Diagram. Identify the possible entity
names and assign a relationship type between the entities.
2. Corresponding Relation of the created E R diagram
Instruction:
 How to draw? 
 Use only your ballpen and paper.
 How to submit the assignment? 
You can take a picture of your work. One photo for the ER
diagram and another one for the corresponding relation of
the created ER diagram. Then, submit the images to the LMS
or email it to tvnakazato@carsu.edu.ph.
 When is the deadline for the assignment? 
On or before September 7, 2020.

You might also like