You are on page 1of 39

IT 220: Database

Management System
By:
Kul P. Paudel
mail@kool.com.np
Paudel.nabu@gmail.com
Note: Please refer course book to explore more knowledge.
Unit 2: Entity Relation Model
LH: 8

IT220: Database Management system,Unit 2, Prepared by Kul P.


04/25/2024
Paudel
 Entities and Entities Sets
Agenda
 Attributes
 Relationships and Relationship Sets
 Keys
 ER Diagram
 Weak entity Sets, Strong Entity Sets, Relationship Sets
 Reducing ER Diagram to Table
 Generalization and Specialization
 Aggregation
 Mapping Cardinalities
 Use of Entity or Relationship Sets
 Use of Extended E-R Features
 Design of an ER Diagram Scheme (Case)
Entities and Entities Sets
A database is model as several entities and relation between those entities.

Entities can be define as an object and which is different from another


object.

In Database one entities is different from another entities. Eg: Employee,
organization, event etc.

An entity set is a set of entities of same type that share the same
properties. Eg: set of all employees, organization etc.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Attributes
An entity is a collection of set of attributes, that is, descriptive
property possessed by all members of an entity set.
Example:
Student =(student_id,student_name,address,gender)
Subject (isbn_no,course_code,course_name)
In the given example “student” and “subject” are entity where as
other object inside small bracket are “attributes”
Domain is a value defined for each attributes.
One attribute is distinguish from another attribute within the given
entity set.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…
Attribute Types
Simple Attributes: The attributes which cannot be divided into smaller subparts
are called simple attributes.
Compound Attributes: Attribute can be subdivided into two or more other
Attribute. For example name can be divided into First Name, Last Name, Middle
Name
Single-valued: An attribute, that has a single value for a particular entity is
known as single valued attributes. For example, age of a employee entity.
Multivalued Attributes: An attributes that may have multiple values for the same
entity is known as multivalued attributes. For Example Phone no. of a person
04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.
Paudel
Cont…
Derived Attributes: Attribute which is derived from other stored attribute. For
example age can be derived from date of birth.
Null Attributes: An optional attribute may not have a value in it and can be
left blank. For example person middle name.
Key Attributes: Attribute which has distinct value for each entity element in
entity set. For example primary key .

Attributes

Compound
Key Attributes Attributes

Multivalued Derived
Attributes Attributes

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Relationships and Relationship Sets

Link between one entities to another is known as relationships


among entities.
eg: Krishna is a student is admit in C101 College
Relationship set is defined as mathematical relation i.e
relation among n>=2 entities, each taken from entity sets.
{(e1,e2, e3,………., en)| e1 ε E1, e2 ε E2,………..,en ε En}
Where (e1,e2, e3,………., en) is a relationship
Example:

where (Krishna,C101) ε admit_in


04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.
Paudel
Cont…
An attribute can be a property of relationship set.
Admit_date
sid sname address college_id name

student admit_in college

Figure: ER Diagram 1

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Keys
Super Key: A super key of an entity set is a set of one or more attributes
whose values uniquely determine each entity
Candidate Key: A candidate key of an entity set is a minimal super key
Primary Key: Several candidate key may exist in a entity, one of the
candidate key is selected as Primary Key
Primary Key uniquely identified the other attributes exist on the entity set.
The combination of primary keys of the participating entity sets forms a
candidate key of a relationship set.
Composite Key: In some entity set a single attribute cannot be used to
uniquely identify entities. In that cases we have to use two or more
attribute to uniquely identifies entities within the entity sets which is
known as composite key.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…
In the above ER-Diagram 1 sid is primary key for student table and
college_id is primary key for college table.
sid and college_id are the combinational primary key for relationship
set admit_in .
Admit_date
sid sname address college_id name

student admit_in college

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram
ER Diagram Component

Rectangles represents Entity sets.

Ellipses represents attributes.

Diamond represents relationship sets.

Lines link attributes to entity sets and entity sets to relationship sets.

Double ellipses represent multivalued attributes.

 Dashed ellipses denote derived attributes.

 Primary key attributes are underlined.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…
ER Symbol

Entity Attributes Connection Multivalued Attributes

Relationship Derived Attributes Weak Entity

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Weak entity Sets, Strong Entity Sets, Relationship Sets

Entity set that does not have a primary is referred as a weak entity set.

it can defined as an entity that cannot be identified by its own attributes.

Weak entity set depends on the another strong entity set.

The primary key of a weak entity set is formed by the primary key of the
strong entity set on which the weak entity set is existence dependent,
plus the weak entity set’s discriminator.

An entity set which has a unique key is known as strong entity set.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…
Weak Entity Example
In the given example departures is a weak entity which do not have its
own unique key so we use attribute date as a key and combine it to
another entity’s (flights) attribute flt_no to form strong entity set.

date
Flt_no dept_time

flights Iinstance_of departures

arr_time flight_name source destination

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Reducing ER Diagram to Table
Primary keys allow entity sets and relationship sets to be expressed
uniformly as tables which represent the contents of the database.
A database which conforms to an E-R diagram can be represented by
a collection of tables.
For each entity set and relationship set there is a unique table which
is assigned the name of the corresponding entity set or relationship
set.
Each table has a number of columns (generally corresponding to
attributes), which have unique names.
Converting an E-R diagram to a table format is the basis for deriving a
relational database design from an E-R diagram.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Example: Reducing to Table
CID Student Course
SID
CID
Name
C_name
DOB
Address
Phone
Enroll

DOB SID
Phone
CID
SID

Address

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Generalization and Specialization
Specialization
Process of designating subgrouping within an entity set is called
specialization.
In terms of ER Diagram, specialization is depicted by a triangle
component labeled ISA.
The ISA (is a) relationship may also be referred as a superclass-
subclass relationship.
Specialization is a top-down approach.
Process of creating new entities from existing entities by including
extra attributes.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…

Generalization:

process of extracting common characteristics from two or more classes


and combining them into a generalized superclass.

Bottom up approach and reverse of Specialization.

Several classes with common features are generalized into superclass

Car, van, bus and truck are generalized into vehicle.

{Car, van, bus, truck}:  Specialization of vehicle

{Vehicle}:  Generalization of {Car, van, bus, truck}


04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.
Paudel
Example
Example: In a a school database, persons can be specialized as teacher
or student based on what role they play in school as entities.
Name Age Gender
Specialization

Generalization
Person

IS A
Rollno Tid

Student Teacher

Class_id shift

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Aggregation
Aggregation is a process when relation between two entities is
treated as a single entity.

A concept which is used to model a relationship between a collection


of entities and relationships. It is used when we need to express a
relationship among relationships.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Example
Job Higher Level Entity

Work
Emp _on
Branch

manage

Manager

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Mapping Cardinalities
express the number of entities to which another entity can be
associated via a relationship set.
One-to-One: An entity in A is associated with at most one entity in B
and vice versa.
One-to-Many: An entity in A is associated with any number (zero or
More) entities in B ,but entity in B is associated with at most one
entity in A.
Many-to-one: An entity in A is associated with at most one entity in B
, but entity in B is associated with any number (Zero or More ) entities
in A.
Many-to-many: An entity in A is associated with any number (zero or
More) entities in B and vice versa.
04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.
Paudel
Example
Country has president. : 1 to 1
University has College. : 1 to M
Teachers teach students. : M to M
Student have principal. : M to 1

Note: Mapping cardinality is depend upon the real world situation.


For example: If in school, a student can be advised by only one advisor
and advisor can advised many students then their exist 1 to M relation
for student to instructor. But a student can be advised by several
instructor then relation for student to instructor is M to M.
Hence Mapping cardinality is depend upon situation.
04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.
Paudel
Participation Constraints
Total Participation: If every entities in E is participate in at least one
relationship in R, then it is said to be total participation

Partial Participation: If only some entities in E is participate in


relationship in R, then it is said to be partial participation.

Total participation Partial Participation :B in A

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Relationship

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Symbol

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram (Case)
Case 1: Construct the clean and concise ER-Diagram for the Following
Scenario.
A bank has many branches in a country. Each branch is identified with
the help of branch name. Each branch of the bank has multiple
customers. Customers also include employees of that particular branch.
An employee can be a manager or staff of that branch. Branch gives
each customer an id in order to identify them. Customers can open two
types of accounts i.e. saving account and Checking account. Branches of
the bank provides Loan to the customers if required. Re-Payment of
loan is done with the help of payment number of that particular loan.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
Cont…

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram (Case)
Case 2: Construct the clean and concise ER-Diagram for the Following
University Database.
There are different university in Nepal. Each college is affiliated with at
most one university. College enrolled student in every academic year in
different faculties. College has department and each department have
some lecturer. Keep in mind that one lecturer is assign to at most one
department and h/she can taught at most one subject to the students.
Students can choose 5 different course in each semester.
Note: Assume your own attributes for each entity. Use different types
of relationship and different types of attributes as per need.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram (Case) Class work
Case 3: Suppose you are given the following requirement for a simple
database for the Everest Premier League (EPL):
The EPL has many teams and each teams has a name, a city, captain,
set of players and coach. Each players belongs to only one team. Players
may be the domestic or overseas. Player has name,role (such as
batsman, wk, bowler, allrounder) ,highest score, no of wkt taken, strike
rate, bowling economy. A team captain is also a player. A game is played
between two team (referred to as a home and away) and has a date
and score. A game is played in home and away stadium.
Construct the ER Diagram for the given scenario.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram (Case)
Case 4: Construct an E-R diagram for a car-insurance company whose
customers own one or more cars each. Each car has associated with it
zero to any number of recorded accidents.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram (Case)
Case 5:Construct an E-R diagram for a hospital with a set of patients
and a set of medical doctors..
Associate with each patient a log of the various tests and
examinations conducted

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram (Case)
Case 6: Consider a database used to record the marks that students
get in different exams of different course offerings.
a) Construct an E-R diagram that models exams as entities, and uses a
ternary relationship, for the above database.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
ER Diagram (Case)
Case 6: b) Construct an alternative E-R diagram that uses only a binary
relationship between students and course-offerings. Make sure that
only one relationship exists between a particular student and course-
offering pair, yet you can represent the marks that a student gets in
different exams of a course offering.

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
NOTE: ER-Diagram can be change and different upon
the scenario and condition used in Scenario

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel
THE END

04/25/2024 IT220: Database Management system,Unit 2, Prepared by Kul P.


Paudel

You might also like