Download as ppt, pdf, or txt
Download as ppt, pdf, or txt
You are on page 1of 26

Entity Relationship Modelling

Entity Relationship Model


Model

A
A
It
It

description of part of real world


starting point to organising stored data
allows discussion of the data
allows semantics verification of the data

Modelling

Using languages or formalisms to describe


models

Entity Relationship (ER) Model


Well-suited database data modelling

It is fairly abstract and is easy to discuss


and explain
It can be readily translated to relations

ER components

Entities: things
Relationships: associations or interactions
between entities

Entities and attributes


Entity

An object or event in the real world


Student, supplier, component

Tangible or intangible
Employee, enrollment

Occurance is more than once


Represented using a name in a box
stude
nt

enrollmen
t

Entities and attributes


Attributes

A set of attributes defines an entity


A student has student Number, name, address,

dob
Each attribute is represented by an oval and is
associated with a domain of legal values
Key attribute is underlined

stude
nt

StudentNo

Name

DOB

Address

Entities and attributes


Instance

An instance of an entity has values for its


attributes: student Mat Ali has address Jl.
Teuku Umar etc.

Composite attribute

An attribute can be composed of many


components
stude
DOB
Jalan
nt
StudentNo

Name

Address

kota
propinsi

Single and Multivalued


Attributes

Most attributes are single-valued


An attribute can have multi values
Part has many colours
Book has many authors
Multi-valued attribute is represented using double

oval

CallNumber
Authors

book

Title
Publisher

Derived Attributes

Attributes that are obtainable from the


values of other attributes / relations
Represented using dash-ed oval
invoic
e

InvNumber
date
Ammou
nt

Relationship
Entities interact using relationship
S1

c1

S2

c2

S3

c3

S4

c4

s5

c5

student

enrollment

course

Relationship
Represented as a diamond
Can have attributes that describe the
relationship
student

enrolls

course

supplier

ship

product

date

InvoiceNo

Recursive Relationship
Entities of the same type can be related
to each other
NoPeg
Name

Employe
e
Address

manages

manag
e

Managed by

Roles
Useful when two entities are related in
more than one way
Owned by

owned

owns

video

shop
located

located

has

Constraints
Cardinality

How often an entity can participate in a


relationship
Relationship can be one-to-one (1:1), oneto-many (1:N), or many-to-many (M:N)

Constraints
If entities A and B have relationship:

One-to-one relationship
Each A is related to at most one B, and vice-versa

employee
E#

Name

has

healthInsurance
Policy
#

Coverages

Constraints

One-to-many relationship
There can be many Bs for each A, but only one A

for each B

employee
E#

Name

lea
d

projec
t

pnumbe
r

Constraints

Many-to-many relationship
There can be many Bs for each A and many As

for each B

student
S#

Name

enroll

course

Course
#

Desc

Participation constraint
Partial

A video rental customer does not have to


have current loans

Total

A video must be in a shop


Total participation is represented using a
double line
N

video

owned

shop

Structural constraint
Defines the (min, max) on participation
of an entity E in relationship R
video

Student

1:N

1:N

owned
enro
ll

1:1

0:N

shop

subject

Weak Entities
Some entities are only meaningful in the
context of a relationship

Dependents of an employee
SPP payment for a student
Those entities are called weak entities and
are represented using a double box
1

student

pay

SPP

ER to Relations: STEP 1

For each non-weak entity E, create a


relation consisting of the simple attributes
of E
Include composite attribute directly
Employee(ssn, bdate, fname, minit,lname, address,
salary)
Department(dnumber, dname,numberofEmployee)
Project(pnumber, pname, location)

ER to Relations: STEP 2

For each weak entity W owned by each


entity E, create a relation consisting of the
simple attributes of W and, as a foreign key,
the key of E
The key is the partial key of W and the
foreign key from E
dependent(ssn, name, sex, birthdate, relationship)

ER to Relations: STEP 3

For each binary 1:1 relationship between


entities with relations S and T, choose, say
S, and include as foreign key in S the
primary key of T
Department(dnumber, dname,numberofEmployee,
mgrssn*)

ER to Relations: STEP 4

For each non-weak binary 1:N relationship


between entities with relations S and T,
where there is one entity in T for many in S,
include the key of T as foreign key in S
Department(dnumber, dname,numberofEmployee,
mgrssn*, pnumber*)
Employee(ssn, bdate, fname, minit,lname, address,
salary, superssn*)

ER to Relations: STEP 5

For each binary N:M relationship between


entities with relations S and T, create a new
relation containing the primary key of S and
the primary key of T (include the
relationship attributes if any)
Works_on(ssn*, pnumber*, hours)

ER to Relations: STEP 6

For each multivalued attribute A of E, create


a relation with an attribute for A and the
key of E. All attributes become they key of
the new relation.
Dept_loc(dnumber*, location)

ER to Relations: STEP 7

For each non-binary relationship, create a


relation with the keys of all the participating
relations.
Lecture(R#, Emp#,
semester, year)
year Course#,
Semester

room
R#

Course

lecture

Course
#

Location

lecturer
Emp#

Name

Desc

You might also like