02 Chapter 02 ER Diagram

You might also like

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

MIT 12063

Database Design and Development

Lesson 03: Entity Relationship


Diagrams
By
S. Sabraz Nawaz
MSc in IS, PGD in IS, BBA (Hons) (Spl. in IS)
MAIS, MIEEE

Senior Lecturer in MIT,


Department of MIT, FMC, SEUSL
ER - Model

• The entity-relationship (ER) data model allows us to describe


the data involved in a real-world enterprise in terms of objects
and their relationships and is widely used to develop an initial
database design

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 2


E-R Model (Entities)

• The two main constructs of the Entity-


Relationship model are Entities &
Relationships
• An entity is an object in the real world that is
distinguishable from other objects
o e.g. Lecturer, Student, Subject, etc.

• A collection of similar entities is called an


entity set
o e.g. Lecturers, Students, Subjects, etc. ENTITY

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 3


E-R Model (Entities...)

Example, an employee in a company database.

e1
e2
e3
e4 EMPLOYEES
e5
e6

Employee Entity set


MIT 12063, Database Design and Development By: S.Sabraz Nawaz 4
E-R Model (Attribute)

• An entity is described using a set of attributes


o e.g. Name, NIC, etc.

• All entities in an entity set have the same attribute

Attribute

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 5


E-R Model (Attributes…)

Example: name, id, age & salary are attributes in


EMPLOYEES entity
salary
salary name
e1
dob e2 id
e3 dob
e4 EMPLOYEES
e5
e6
id

name
Employee Entity set
MIT 12063, Database Design and Development By: S.Sabraz Nawaz 6
E-R Model (Attributes…)

• The attributes are said to be composite if they can be split.


Eg:- the entity Employee contains attribute 'name' which is a
composite one

name
EMPLOYEES

LastName FirstName

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 7


E-R Model (Attributes…)

• A multi-valued attribute of an entity is one which has


multiple values.
o Eg:- attribute phone numbers in employee entity.

EMPLOYEES

surname first_name phone

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 8


E-R Model (Attributes…)

• Some attributes that can be computed from other attributes are


called derived attributes.
o Eg:- age is derived from date of birth & current date

EMPLOYEES

dob age
name

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 9


E-R Model (Attributes…
another sample)

Customers

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 10


Practice

• Applying the attributes learned, draw an entity named Student


with most relevant attributes

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 11


E-R Model (Domain)

• Each attribute in an entity set has domain; possible values


o e.g. Age attribute of an employee has possible integer values from 18-60

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 12


E-R Model (Keys)

• A Key is a minimal set of attributes whose values uniquely


identify an entity in the set

salary name
e1
dob e2 id
e3
e4
e5
e6 Employee Entity set

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 13


E-R Model (Keys...)

• A candidate key is a combination of attributes that can be


uniquely used to identify a database record

• If a table has one or more candidate keys, one of these


candidate keys is selected as the table primary key and the rest
are called alternate keys
EMPLOYEES
• Primary key is underlined

id

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 14


E-R Model (Keys...)

• A key formed by combining at least two or more columns is


called composite key

• Always, the minimal set of attributes are considered for the


key.

• Therefore,
A key is a minimal set of attributes whose values uniquely
identify an entity in the set.

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 15


E-R Model (Relationship)

• A relationship is an association among two or more entities


o SaNa works for Department of MIT
o Thilan works for Department of MIT

• A collection of similar relationships is called a relationship


set

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 16


E-R Model (Relationship…)

Graphically,

EMPLOYEES works DEPARTMENTS


in

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 17


E-R Model (Relationship…)

• A relationship can also have attributes which are called as


descriptive attributes
• These are used to record information about the relationship
o E.g. SaNa works for MIS Department from November 2006. In the figure, this
is captured by the since in Works_In

nic dob

18
MIT 12063, Database Design and Development By: S.Sabraz Nawaz
E-R Model (Relationship…)

1/2/97

111 1/2/99
D1
222
1/5/01
D2
333
1/2/87
D3
444
1/3/95

Departments
Employees
Work_in
MIT 12063, Database Design and Development By: S.Sabraz Nawaz 19
E-R Model (Relationship…)

An instance of a relationship set is the set of relationships

1/1/91

111 3/3/93
D1
222 2/2/92
D2
333 3/1/92
D3
444
3/1/92

Departments
Employees
Work_in
MIT 12063, Database Design and
20
Development By: S.Sabraz Nawaz
E-R Model (contd.)

• Degree of a relationship is the number of participating


entities in the relationship.

• A relationship of degree two is called a binary relationship


(e.g. Works In)

• A relationship with degree three is called ternary.

MIT 12063, Database Design and


21
Development By: S.Sabraz Nawaz
E-R Model (contd.)

Ternary relationship

D1
111
D2 Departments
222

333 D3

444

Employees
L1

Work_in L2
Locations
L3
MIT 12063, Database Design and
22
Development By: S.Sabraz Nawaz
E-R Model (contd.)

Ternary relationship

works DEPARTMENTS
EMPLOYEES
in

LOCATIONS

MIT 12063, Database Design and


23
Development By: S.Sabraz Nawaz
E-R Model (contd.)

• The cardinality ratio for a binary relationship


specifies the number of relationship instances that an
entity can participate in.
• There are three types of cardinality ratios for binary
relationships.
o One-to-One
o One-to-Many (Many-to-One)
o Many-to-Many

MIT 12063, Database Design and


24
Development By: S.Sabraz Nawaz
E-R Model (contd.)

One-to-One relationship

Example: An employee manages at most one department. A


department can have only one manager managing it.

EMPLOYEES manages DEPARTMENTS

MIT 12063, Database Design and


25
Development By: S.Sabraz Nawaz
E-R Model (contd.)

One-to-Many relationship
For example, an employee works in at most one department.

Graphically,

EMPLOYEES works
DEPARTMENTS
in

MIT 12063, Database Design and


26
Development By: S.Sabraz Nawaz
E-R Model (contd.)

Many-to-Many relationship

Example: An employee can work on several projects. A project


can have many employees working on it.

works
EMPLOYEES PROJECTS
on

MIT 12063, Database Design and


27
Development By: S.Sabraz Nawaz
E-R Model (contd.)
• Participating constraint specifies whether the existence of an
entity depends on its being related to another entity via the
relationship type
• For example, if we specify that an employee must always work
for a department. Then we say that the relationship “works in” is
in total participation from Employee entity to Department entity

EMPLOYEES works in DEPARTMENTS

• If the relationship is not in total participation, then it is known as


in partial.
o For example, from DEPARTMENTS to EMPLOYEES

MIT 12063, Database Design and


28
Development By: S.Sabraz Nawaz
E-R Model (contd.)

• Entity types without any key attributes is called weak entity types.
• A weak entity is uniquely identified by considering some of its
attributes with the primary key of another entity called the
identifying owner.
• The attributes in the weak entity participating in the key are called
partial keys
• The owner entity and the weak entity participates in an identifying
relationship.
• The cardinality of the identifying relationship is either one-to-one
or one-to-many from owner entity to weak entity
• The weak entity must have total participation in the identifying
relationship
MIT 12063, Database Design and
29
Development By: S.Sabraz Nawaz
E-R Model (contd.)

Graphically (Weak Entity)

1 M
EMPLOYEE Policy DEPENDENTS

id name age

MIT 12063, Database Design and


30
Development By: S.Sabraz Nawaz
E-R Model (contd.)
• Entities participating in a relationship need not be distinct.
Such relationships are called recursive relationships.
• Each entity in the relationship play a role in the relationship. It
is recommended to state the role in recursive relationships.

manages

supervisor subordinate

EMPLOYEES
MIT 12063, Database Design and
31
Development By: S.Sabraz Nawaz
Reference:
Ramakrishnan, R., & Gehrke, J. (2003). Database management
systems. Osborne/McGraw-Hill. (p. 24-50)

MIT 12063, Database Design and Development By: S.Sabraz Nawaz 32

You might also like