You are on page 1of 89

Data Modeling : ER Model

N. L. Sarda
I.I.T. Bombay

m
` y `e Model
O `e build models of complex systems
because we cannot compre end any suc
system in its entirety
O Need to develop a common understanding of
t e problem and t e solution
O Cannot afford a trial-and-error approac
O to communicate t e desired structure and
be avior of our systems


` y `e Model«
to visualize and control system¶s
arc itecture
to understand t e system we are building,
often exposing opportunities for
simplification and reuse
to manage risk

2
¦ow `e Model
O T e c oice of w ic model we use as a
profound influence on ow a problem is
attacked and ow a solution is s aped
O No single model is sufficient; every complex
system is best approac ed t roug a set of
independent models
Every model may be expressed at different
levels of fidelity
O T e best models are connected to reality

á
ë TLINE
Data model
Concepts of entity and relations ips
E-R diagramming
Keys
`eak entities
Extended E-R model


DATA MëDEL
for representation of a part of a real world
it is an abstraction of t e reality : ignores
unnecessary details
represents operational data about real world
events, entities, activities, etc.
model may be at various levels depending of
requirements :
logical or p ysical
external, conceptual, internal

½
Data Model««
a good model
is easy to understand
as a few concepts
permits top-down specifications
model offers concepts, constructs and
operations
must capture meaning of data (data
semantics) w ic elp us in interpreting and
manipulating data

0
Data Model««
semantics captured t roug data types,
inter-relations ips and data integrity
constraints
uniqueness
existence dependence
restrictions on some operations suc as
insertions, deletions

u
Example : Data Model in a PL
data structuring concepts
data field/variable
data groups and arrays
Record/structure : unit of file i/o
file : collection of records

º
Example : Data Model in a PL «
ëperations
file level : open, close
record level :
read next/random
write next/random
field level : computations
no inter-file and inter-record relations ips
no constraints except primary key for
indexed files

m
ENTITY-RELATIëNS¦IP (ER)
MëDEL
for representation of real-world
represents overall logical structure of
information
grouping of data elements
inter-relations ips between groups

mm
ER MëDEL«.
a few concepts
simple and easy-to-use
permits top-down approac for controlling
details
useful as a tool for communication
between designer and user during
requirements analysis and conceptual
design

m
ENTITY
an object t at exists
distinguis able from ot er objects
could be concrete or abstract
Examples : a book, an item, a student, a
purc ase order
(a/an above indicates t at we are referring to
one of t ese)

m2
ENTITY SET
a set of similar entities
need not be disjoint wit ot er entity sets
e.g., supplier and customer may ave common
entities
Example : set of all books in a library
set of all customers
entity set also called entity type or entity
class
entity considered as an occurrence of entity
type

ENTITY SET««
we often use t e words µentity¶ to mean
µentity-set¶
entity sets are named using singular
common nouns :
Book
Student
Course


ATTRIB TE
an entity as a set of attributes
attribute defines property of an entity
it is given a name
attribute as value for eac entity
value may c ange over time
same set of attributes are defined for entities
in an entity set


ATTRIB TE«.
Example : entity set BëëK as t e following
attributes
TITLE ISBN
ACC-Në A T¦ëR
P BLIS¦ER YEAR
PRICE
a particular book as value for eac of t e
above attributes

m0
ATTRIB TE«.
an attribute may be multi-valued, i.e., it as
more t an one value for a given entity; e.g., a
book may ave many aut ors
an attribute w ic uniquely identifies entities
of a set is called primary key attribute of t at
entity set
composite attribute : date, address, etc

mu
DëMAIN
gives set of permitted values for an attribute
all values may not be present at all times in
database
may be defined by type : integer, string
attributes are µroles¶ played by domains
domain µpersonname¶ can be used for attribute
µname¶ for teac er and student entities


EXAMPLE : A CëLLEGE
ST DENT : rollno, name, ostel-no., date-
of-birt
Cë RSE : courseno, name, credits
TEAC¦ER : empno, name, rank, room-no.,
tel-p one
DEPT : name, tel-p one


EXAMPLE : A CëLLEGE«
t is example will be refined furt er
perception of reality and focus of design
could ave indicated more entities
¦ëSTEL SEMESTER
ër, teac er could only be an attribute

EXERCISE : identify entities in a ospital and


give a few instances of eac

m
RELATIëNS¦IP
represents association among entities
e.g., a particular book is a text for particular
course
book µDatabase Systems¶ by C.J. Date is text for
course identified by code µCS644¶
e.g., student GANES¦ as enrolled for
course CS644


RELATIëNS¦IP SET
set of relations ips of same type
words µrelations ip¶ and µrelations ip set¶
often used interc angeably
between certain entity sets
binary relations ip : between two entity sets
ternary relations ip : among t ree entity sets

2
RELATIëNS¦IP SET«.
e.g., binary relations ip set ST DY between
ST DENT and Cë RSE
relations ip ST DY could be ternary among
ST DENT, Cë RSE and TEAC¦ER
` at is t e difference ?
a relations ip may ave attributes
e.g., attribute GRADE and SEMESTER for ST DY


RELATIëNS¦IP SET«.
relations ips named using verbs or nouns
Study
Enroll
ërder

EXERCISE : identify relations ips and t eir


attributes in t e ospital example and give a
few instances of eac


DEPICTING A RELATIëNS¦IP
entity sets as a collection
entity instances by small circles
relations ip instances by small rectangle
wit connections to involved entities


0
RELATIëNS¦IP CARDINALITY
is a constraint on a relations ip
it c aracterizes relations ips furt er
given as (mapping) cardinality : ow many
entities of an entity set participate in a
relations ip
especially useful for binary relations ips

u
RELATIëNS¦IP CARDINALITY«
a relations ip set R between entity sets A
and B may be one of t e following
one-to-one : one entity in A associated wit at
most one entity in B
one-to-many : one entity in A may be associated
wit zero/more number of entities in B.
¦owever, one entity in B can be associated wit
at most one entity from A.
many-to-one : reverse of above definition (like a
mat ematical function)


RELATIëNS¦IP CARDINALITY«
many-to-many : one entity in A may be
associated wit any number of entities in B, and
vice-versa.
EXAMPLES :
relations ip set TEAC¦ES from TEAC¦ER to
Cë RSE is one-to-many
(TA G¦T-BY from Cë RSE to TEAC¦ER is
many-to-one)
relations ip ST DY between ST DENT and
Cë RSE is many-to-many

2
EXISTENCE DEPENDENCE
existence dependency : anot er important
constraint
existence of entity µa¶ may depend on existence
of anot er entity µb¶:
µb¶ is called dominant entity and µa¶ is called
subordinate entity

2m
EXISTENCE DEPENDENCE«
t ere exists existence dependency of
TEAC¦ER on DEPT as no teac er can be
appointed wit out fixing er department
Subordinate entity as its own key and may
participate in more relations ip

2
22

?  ?
 


‡ G      
‡        

20
2u

‡ Describe the real-world mapped above in words.
‡ Can you represents this : a supplier may supply same part many times
Note : Relationship µsupplies¶ could also be ternary
(by involving warehouse)
á
TERNARY RELATIëNS¦IPS
be sure t at your model reflects real-world
correctly
ternary (or, of ig er order) relations ips are
arder to understand
is a ternary equivalent to two binary? if not,
w ic one is correct in a given situation?

ám
TERNARY RELATIëNS¦IPS«
consider s ipments data w ere parts are
supplied to projects by suppliers in certain
quantities; given :
S1 supplies 40 number of P1 to J1
we lose context if we replace it by
S1 supplies 40 of P1
S1 supplies to J1
t us, ternary relations ip is not same as two
binary relations ips

á
á2
áá
PRIMARY KEYS
to distinguis occurrences of entities and
relations ips
distinction made using values of some
attributes
superkey : set of one/more attributes w ic ,
taken collectively, uniquely identify an entity
in an entity set
superkey may contain extraneous attributes

á
PRIMARY KEYS«..
e.g., rollno is sufficient to identify students
it is a primary key
combination (rollno, name) is a superkey
name itself may not be sufficient as key
candidate key is minimal superkey. No
subset of it is a superkey
an entity may ave multiple candidate keys
primary key is a candidate key c osen by
designer as t e principal means of
identification
á½
PRIMARY KEY FëR
REPATIëNS¦IPS
made of primary keys of all participating
entities e.g., primary key of ST DY is
(rollno, courseno)

á0
`EAK ENTITY
does not ave a primary key on its own
t ey are related to one/more µstrong¶ entities
t ey often can be visualized as multivalued
attribute or group of attributes
t ey eit er ave a µpartial¶ key or we add
one to distinguis between t ose w ic are
related to same strong entity

áu
`EAK ENTITY«
examples:
branc es of a bank
interviews between candidates and companies
viewed as entities (not relations ips) so t at
t ey can participate furt er in relations ips
E-R diagrams follow

áº

`EAK ENTITY«
partial key (BrName in example) also called
discriminatory attribute
a weak entity can participate furt er in
relations ips wit ot er entities
a weak entity can also ave weak entities
dependent on in
primary key of weak entity = primary key of
its strong entity + discriminating attribute of
weak entity wit in t e context of strong
entity
m
‡   
   
‡  ?   !

EXERCISE (Post-Graduate studies)
Students join a particular specialization offered by a
department. A specialization wit same title (e.g.,
MICRëCëMP TER) may be offered by one/more
depts independently. Teac ers are appointed to a
specific dept, and given a room and telep one.
Depts ave some teac er as its ead. Courses are
offered under various specializations. A teac er
may teac many courses and a course may be
taug t by many. A student studies a course under
a teac er during some semester (e.g., semester 1 of
1989), and is awarded a grade. A teac er¶s
researc interest may lie in one/more
specializations. Courses ave one/more/zero
prerequisites
2
EXTENDED E-R MëDEL
extensions to capture more meaning
concepts of generalization, aggregation and
sub-set ierarc ies added
Similar to ëë concepts : in eritance, composite
objects

á
Generalization
to generalize from two or more entity sets
and factor out commonality
entity E is generalization of entities E1, E2,
E3 « if eac instance of E is also an
instance of one and only one of E1, E2, etc.;
E called superclass of E1, E2, «
represented by IS-A relations ip


Generalization«

Example : given two entities Faculty and


Non-faculty,we can define a µgeneral¶ entity
called Employee
Common attributes are factored out to
define µEmployee¶ entity; specific (non-
common) attributes incorporated in µFaculty¶
and µNon-faculty¶ entities

½
0
Gnother example :

u
Specialization
also called subset ierarc y
entity E1 is subset of E if every instance of
E1 is also an instance of E; t is is also IS-A
relations ip
E called superset and E1 as subset (or sub-
class); E may ave multiple and possibly
over-lapping subsets
every instance in E need not be present in
subsets of E

º
Specialization«..
specialization allows classification of an
entity in subsets based on some
distinguis ing attribute/property
we may ave several specialization of same
entity
t e subsets may ave additional attributes

½
½m
In eritance
t ere is in eritance of attributes from
superclass or superset
t e subclass/subset automatically in erits
attributes defined at superclass/superset
level
t us, in eritance present in bot
Generalization and specialization
Direction important : bottom-up in
generalization, top-down in Specialization
Important to distinguis t e two cases

½
Aggregation
for building complex entity from existing
entities (or existing entities and
relations ips)
two ways of defining complex entities :
create an attribute w ose value is anot er entity
define an entity as containing a group of related
entities

½2
Examples :
`ork-order object (entity) defined as
consisting of entities Raw-material, Tools
and `orkers;
`ork-order itself related wit Customer
entity
Aggregation notation not explicitly provided
in Extended E-R model

½á
Work-order
Raw Material Tools

`orker

Customer

 obNo Quantity

½
(ANS`ER Të EXERCISE)

½½
Going from E-R to Relational Data
Model
Need to match
ER model concepts : entity, relationship, attribute
with
Relational model concepts : relation, attribute

entity àtudent ( rollno, name, «. )


àtudent

rollno name «.

½0
E-R to Relational «

1 1
1:1 Dept Mgr

DNo «« MName ««

DEPT (DNo , «««. , MName )


MGR (MName , ««, DNo )

also keys; in one or both


½u
E-R to Relational «

1 m
Ôank Ôranch Client

GCno Name ««
ÔName Loc ««

Ô Ôranch (ÔName , Loc , «««. )


Client (Name , ««, ÔName , Loc , GCno )
The relationship is included in the entity on µmany¶ side;
It includes primary key of entity on µone¶ side and
Relationship attributes, if any
½º
E-R to Relational «

m m
àtd Reg Course

R# «« Grade C# ««

àTD (R# , «««. )


COURàE (C# , «« )
REG (R# , C# , Grade)

0
Exercise: Airport database
keeps track of airplanes, t eir owners, airport
employees and pilots
Eac airplane as a registration number, is of a
particular plane type and is stored in a particular
anger. Eac plane type as a model number,
capacity and weig t. Eac anger as a
number, capacity and location. T e database
also keeps track of w o owns w ic plane.
Persons ave name, address and p ones. A
person buys a plane on a particular date and
cost.

0m
Airport database«.
Eac plane undergoes service many times. A
service information contains date of work,
nature, ours spent, cost, etc. Pilots and
employees are persons. Pilots ave a license
number wit validity and salary. Employees
ave a number, rank and salary. Eac pilot is
aut orized to fly certain types of planes.
Employees are involved in servicing of planes.
prepare E-R model
convert to t e relational model

0
Exercises

Prepare E-R models and convert to relational


sc ema

Railway Reservation
30 days in advance
trains, stations, quotas, coac es
passengers, tickets, wait-list, etc.

02
Exercises«
ëld Car Mart
buying and selling of old cars
cars, purc ases, sales ± direct or installment-
wise
service to sold cars, pre-sale repairs
agents
Cricket Database
countries, players, teams
matc es, results, scores
Prepare sample data


Exercise : Portfolio Management
for individual investors
investments are made in s ares,
debentures, bonds, National saving
certificates, various sc emes like PPF,
ELSS, mutual funds, etc.
t ese may be acquired at public issue time,
purc ased from market, obtained as bonus
(free), on µrig ts-basis¶, etc.


Portfolio «
some investments ave regular returns;
e.g., yearly, 6-mont ly, etc. at fixed or
announced rates
t ese will be sold in market or re-deemed,
converted, etc.
ow, w en and ow muc invested, w at
returns already obtained are important for
t e investor to know ow good are is
investments. At year end, e may wants
to know t e market value of is
investments

Portfolio «
Exercise :
Draw E-R diagram
convert to relational sc eme
c eck if all relations are in 3NF

00
* ALITY AND CëMPLETENESS
C¦ECKS
ENTITIES
are t ey really entities? i.e., t ings of real
significance about w ic information needs to
be eld
C ecklist
singular meaningful name
mutual exclusivity
at least 2 attributes ( and < 8 )
synonyms/ omonyms
full definition

0u
* ALITY AND CëMPLETENESS
C¦ECKS«
ENTITIES (C ecklist«)
volumetric information
a unique identifier
at least one relations ip
at least one business function to create, update,
delete, arc ieve and use t e entity
c anges over time
it (functionally) determines its attributes
is it too generic ?
is it sufficiently generic ?


* ALITY AND CëMPLETENESS
C¦ECKS«
ATTRIB TES
do t ey really describe t e particular entity ?
C ecklist
singular meaningful name
name not to include entity name
only one value : no repeating / group value
complete metadata (format, allowed values, etc.)
is it really an entity
value depends only on t e entity (not on part of
identifier or some ot er attribute)

u
* ALITY AND CëMPLETENESS
C¦ECKS«
Relations ips
are t ey really significant associations ?
C ecklist
eac end named and capable of being read
accurately and sensibly
eac end as a degree and optionality
is it redundant
does it cater for time
c eck arity
Try populating t e E-R model

um
Entity/Process Matrix
after building data model and defining
elementary processes, create a matrix wit
entities along columns, processes along
rows
fill entries indicating w ic processes create
entities, and w ic read, update and delete
t e entities
Also called CR D (Create, Read, pdate and
Delete) matrix

u
Relations ips between diagrams
FDD identifies processes
T ese processes s own in DFDs
DFDs give process dependencies wit data
interactions added
Data stores in DFDs are basis for E-R
diagram
T ese t ree diagrams s ould be consistent

u2
ENTITY LIFE ¦ISTëRY (EL¦)
depicts pictorially t e events affecting life of
an entity from creation to deletion
dynamic istory : state c anges over time
are depicted
events may be triggered by input or time
possible effects of events : creation,
deletion, modify attributes of entities,
relations ips or bot
EL¦ Notation


ENTITY LIFE ¦ISTëRY (EL¦)..
‡ ?"# 


ENTITY LIFE ¦ISTëRY (EL¦)..
EL¦ is a tree wit an
entity type as its root
Event compositions
sequence of E1 and E2


ENTITY LIFE ¦ISTëRY (EL¦)..
Selection : e1 or e2 ( one-of )

‡  

u0
ENTITY LIFE ¦ISTëRY (EL¦)..
‡


uu
ENTITY LIFE ¦ISTëRY (EL¦)..

‡ è      

You might also like