You are on page 1of 83

:6

Entity--Relationship
Entity
Instructor: Reza Godaz
Azad University of Mashhad

Database System
y
Concepts,
p , 5th Ed.
Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Database System Concepts - 5th Edition, Oct 5, 2006

6.1

Silberschatz, Korth and Sudarshan

:6 Entity--Relationship
Entity


E-R
E
R



) (Weak Entity Sets
ER-R ) (Extended E-R



UML

Silberschatz, Korth and Sudarshan

6.2

Database System Concepts - 5th Edition, Oct 5, 2006


:
:
z


)

:
(.

: E-R
.

: functional .

:
z

) ( E-R ) (
:

: DBMS oracle SQL


Server ...

Silberschatz, Korth and Sudarshan

6.3

Database System Concepts - 5th Edition, Oct 5, 2006


ER ) (entities
) (relationships
.

z :
) (attributes
z : .
) (entity set .
z .

Silberschatz, Korth and Sudarshan

6.4

Database System Concepts - 5th Edition, Oct 5, 2006

loan customer
customer_id customer_ customer_ customer_
name street
city

Database System Concepts - 5th Edition, Oct 5, 2006

6.5

loan_
number

amount

Silberschatz, Korth and Sudarshan


.( relationship )
:

A-102
account entity

depositor
relationship set

Hayes
customer entity

n 2
.
{(e1, e2, en) | e1 E1, e2 E2, , en En}
.( e1, e2, , en)
:
z
(Hayes, A-102) depositor

Database System Concepts - 5th Edition, Oct 5, 2006

6.6

Silberschatz, Korth and Sudarshan

borrower

Database System Concepts - 5th Edition, Oct 5, 2006

6.7

Silberschatz, Korth and Sudarshan

)(
) (attribute .
customer account


depositor

access-date .

Silberschatz, Korth and Sudarshan

6.8

Database System Concepts - 5th Edition, Oct 5, 2006



.
) 2 (
.
.

.

 :
3 . 3
employee job branch )
(.
(

Silberschatz, Korth and Sudarshan

6.9

Database System Concepts - 5th Edition, Oct 5, 2006

)(Attributes

.

:
customer = (customer_id, customer_name,
customer_street,
t
t t customer_city
t
) it
) loan = (loan_number, amount
) : (Domain .
:
z

) (Simple ) . (composite

- ) (Single-valued - )(multi-valued
 - phone_numbers :

z (Derived attributes) :

 age date_of_birth .
Silberschatz, Korth and Sudarshan

6.10

Database System Concepts - 5th Edition, Oct 5, 2006

Database System Concepts - 5th Edition, Oct 5, 2006

6.11

Silberschatz, Korth and Sudarshan


)(Mapping Cardinality Constraints
.








.
:
z
z
z
z

Silberschatz, Korth and Sudarshan

6.12

Database System Concepts - 5th Edition, Oct 5, 2006

.




A B

:
Silberschatz, Korth and Sudarshan

6.13

Database System Concepts - 5th Edition, Oct 5, 2006

.




A B

:
Silberschatz, Korth and Sudarshan

6.14

Database System Concepts - 5th Edition, Oct 5, 2006

)(Keys
) (super key
.
) (candidate key
.
z

Customer_id customer.

account_number account.




) (primary key
.

Silberschatz, Korth and Sudarshan

6.15

Database System Concepts - 5th Edition, Oct 5, 2006



.
z ) (customer_id, account_number depositor.
z :
.
 access_dates account customer





.

.

Silberschatz, Korth and Sudarshan

6.16

Database System Concepts - 5th Edition, Oct 5, 2006

E-R

.
.

.
.


z
z .
.
Silberschatz, Korth and Sudarshan

6.17

Database System Concepts - 5th Edition, Oct 5, 2006

E-R

Database System Concepts - 5th Edition, Oct 5, 2006

6.18

Silberschatz, Korth and Sudarshan

Database System Concepts - 5th Edition, Oct 5, 2006

6.19

Silberschatz, Korth and Sudarshan

)(Roles
) (



worker

manager k



employee works_for
.
E-R
.

Silberschatz, Korth and Sudarshan

6.20

Database System Concepts - 5th Edition, Oct 5, 2006

Cardinality
)( 1 ) (one, )(
(many.
) many,
--:
z borrower .
z borrower .

Silberschatz, Korth and Sudarshan

6.21

Database System Concepts - 5th Edition, Oct 5, 2006

(One
One--To - )To-Many
) ( borrower
) ( borrower
.

Silberschatz, Korth and Sudarshan

6.22

Database System Concepts - 5th Edition, Oct 5, 2006

(Many
Many--To -- )To-One
) ( borrower
borrower .

Silberschatz, Korth and Sudarshan

6.23

Database System Concepts - 5th Edition, Oct 5, 2006

(Many
Many--To
-- )To--Many
) ( borrower



borrower
b
(

)


Silberschatz, Korth and Sudarshan

6.24

Database System Concepts - 5th Edition, Oct 5, 2006


) : (
.

:
.
z borrower customer
.


Silberschatz, Korth and Sudarshan

6.25

Database System Concepts - 5th Edition, Oct 5, 2006


) --
loan customer (borrower

Silberschatz, Korth and Sudarshan

6.26

Database System Concepts - 5th Edition, Oct 5, 2006

E-R

Database System Concepts - 5th Edition, Oct 5, 2006

6.27

Silberschatz, Korth and Sudarshan




works_on job
) (.
:
z R A B C B C .
:

.1 A B C
.2 ) (A, B C ) (A, C
.
B
z
z .

Silberschatz, Korth and Sudarshan

6.28

Database System Concepts - 5th Edition, Oct 5, 2006


) (
.
) 15-6 ( 74 emploee

emp_name
emp name

(...

.
)
(
(

.



.
) (34

Silberschatz, Korth and Sudarshan

6.29

Database System Concepts - 5th Edition, Oct 5, 2006







) (parentt


z

.
 -
) .
(
z
) (works_on

Silberschatz, Korth and Sudarshan

6.30

Database System Concepts - 5th Edition, Oct 5, 2006

R A B C E RA
RB RC

E ) ei identifying attribute (
z
.1

) (ai , bi , ci R :
ei E

.2

) (ei , ai RA .

.3

) (ei , bi RB .

.4

) ((ei , ci RC .

Silberschatz, Korth and Sudarshan

6.31

Database System Concepts - 5th Edition, Oct 5, 2006

)(

:
.




z
z R
.
 : RA RB RC

A B C .

z identifying attribute E
.

Silberschatz, Korth and Sudarshan

6.32

Database System Concepts - 5th Edition, Oct 5, 2006

ER
access-date account



account


z .







z :
. access-date
) account ( .



).
(

Silberschatz, Korth and Sudarshan

6.33

Database System Concepts - 5th Edition, Oct 5, 2006

How about doing an ER design


i t
interactively
ti l on the
th b
board?
d?
Suggest an application to be modeled.

Database System
y
Concepts,
p , 5th Ed.
Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Database System Concepts - 5th Edition, Oct 5, 2006

6.34

Silberschatz, Korth and Sudarshan


)(Weak Entity Sets


.



)

) (identifying entity set


(
.


z
.
.

) discriminator (partial key
.
discriminator





Silberschatz, Korth and Sudarshan

6.35

Database System Concepts - 5th Edition, Oct 5, 2006

)(


underline
d li

) (payment_number
payment )(loan_number, payment_number
.

Silberschatz, Korth and Sudarshan

6.36

Database System Concepts - 5th Edition, Oct 5, 2006

)(

:
.
strong
payment

loan_number
loan number


) ( payment loan
loan_number payment loan
.

Silberschatz, Korth and Sudarshan

6.37

Database System Concepts - 5th Edition, Oct 5, 2006


) course (
) course_offering (
.
.
) semester course_offering ( ) section_number
( .
course_offering
course offering

course_number .
course course_number
.


Silberschatz, Korth and Sudarshan

6.38

Database System Concepts - 5th Edition, Oct 5, 2006

: E-R
)(Specialization
(
)






.

. .
ISA.
( customer is
is a
) a person
) : (Attribute inheritance
.

Silberschatz, Korth and Sudarshan

6.39

Database System Concepts - 5th Edition, Oct 5, 2006

Specialization

Database System Concepts - 5th Edition, Oct 5, 2006

6.40

Silberschatz, Korth and Sudarshan

: E-R)(Generalization
:
.
ER
.

Silberschatz, Korth and Sudarshan

6.41

Database System Concepts - 5th Edition, Oct 5, 2006

( )Generalization Specialization

.
( permanent_employee )
teller secretary officer ( permanent_employee )
:
temporary_employee, permanent_employee z
teller secretary officer

z
. superclass subclass ISA

Database System Concepts - 5th Edition, Oct 5, 2006

6.42

Silberschatz, Korth and Sudarshan


Specialization/Generalization
p

:
z )(condition-defined
 : 65
. senior-citizen ISA
senior-citizen S person
z )(user-defined


:
z )(Disjoint
 .

disjoint ISA
E-R
E R

z )(Overlapping
.



Silberschatz, Korth and Sudarshan

6.43

Database System Concepts - 5th Edition, Oct 5, 2006


) Specialization/Generalization(

: (Completeness
C
l t
constraint
) t i t



.
::



z ) :(total
.
z ) :(partial
.

Silberschatz, Korth and Sudarshan

6.44

Database System Concepts - 5th Edition, Oct 5, 2006


(Aggregation
))Aggregation
works_on
.
manages job branch
emploee.


works_on manages
works on


job branch emploee .

Silberschatz, Korth and Sudarshan

6.45

Database System Concepts - 5th Edition, Oct 5, 2006

)(
works_on manages overlap.
works_on.
k



manages
z
z works_on manages).
(
 works_on .
.
z .
z .
:

z
z branch jjob emploee .

Silberschatz, Korth and Sudarshan

6.46

Database System Concepts - 5th Edition, Oct 5, 2006

E-R Diagram With Aggregation

Database System Concepts - 5th Edition, Oct 5, 2006

6.47

Silberschatz, Korth and Sudarshan

E-R
.










.


.

specialization/generalization
p
g



modularity
.
aggregation

) (

Silberschatz, Korth and Sudarshan

6.48

Database System Concepts - 5th Edition, Oct 5, 2006

ER

Database System Concepts - 5th Edition, Oct 5, 2006

6.49

Silberschatz, Korth and Sudarshan

How
H
about
b t doing
d i another
th ER design
d i
interactively on the board?

Database System
y
Concepts,
p , 5th Ed.
Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Database System Concepts - 5th Edition, Oct 5, 2006

6.50

Silberschatz, Korth and Sudarshan

ER

Database System Concepts - 5th Edition, Oct 5, 2006

6.51

Silberschatz, Korth and Sudarshan

()ER

Database System Concepts - 5th Edition, Oct 5, 2006

6.52

Silberschatz, Korth and Sudarshan




ER .

.



) (
.

Silberschatz, Korth and Sudarshan

6.53

Database System Concepts - 5th Edition, Oct 5, 2006





.
= payment
) ( loan_number, payment_number, payment_date, payment_amount

Silberschatz, Korth and Sudarshan

6.54

Database System Concepts - 5th Edition, Oct 5, 2006



.
: : borrower
) borrower = (customer_id, loan_number

Silberschatz, Korth and Sudarshan

6.55

Database System Concepts - 5th Edition, Oct 5, 2006

: account_branch
branch_name account .

Silberschatz, Korth and Sudarshan

6.56

Database System Concepts - 5th Edition, Oct 5, 2006

)(

.

z
.


.

.
z : payment loan_payment
) loan_number ( payment_number

Silberschatz, Korth and Sudarshan

6.57

Database System Concepts - 5th Edition, Oct 5, 2006


(Composite
p
))and Multivalued Attributes

.
z : customer name first_name
last_name
name.last_name.
name.first_name name last name
name first name
M E EM .
z EM E M
.
z : dependent_names employee
:


)employee_dependent_names = ( employee_id, dname
EM










z
.
 : employee 123-45-6789 Jack
Jane ) (123-45-6789 , Jack
) (123-45-6789 , Jane .
Silberschatz, Korth and Sudarshan

6.58

Edition, Oct 5, 2006

5th

Database System Concepts -


Specialization
p

:1






z
z

.:
attributes
name street,
name,
street city
name, credit_rating
name, salary

schema
person
customer
employee

z : employee
.

Silberschatz, Korth and Sudarshan

6.59

Database System Concepts - 5th Edition, Oct 5, 2006

)(
Specialization

) :2 disjoint total(




z
.
attributes
name, street, city
name, street, city, credit_rating
name, street, city, salary

schema
person
customer
employee

(p
g )person
z total generalized
.
 view .
.










z street : city customer employee
.

Silberschatz, Korth and Sudarshan

6.60

Database System Concepts - 5th Edition, Oct 5, 2006





z
z
.

Silberschatz, Korth and Sudarshan

6.61

Database System Concepts - 5th Edition, Oct 5, 2006

)(

: manages works_on
manager :
)manages (employee_id, branch_name, title, manager_name
works_on
works on
manager_name manages .

Silberschatz, Korth and Sudarshan

6.62

Database System Concepts - 5th Edition, Oct 5, 2006

UML
UML: Unified Modeling Language
UML h
has many components
t tto graphically
hi ll model
d l diff
differentt aspects
t off an

entire software system


UML Class Diagrams correspond to E-R Diagram, but several

differences.

Database System Concepts - 5th Edition, Oct 5, 2006

6.63

Silberschatz, Korth and Sudarshan

Summary of UML Class Diagram Notation

Database System Concepts - 5th Edition, Oct 5, 2006

6.64

Silberschatz, Korth and Sudarshan

UML Class Diagrams (Cont.)


Entity sets are shown as boxes, and attributes are shown within the

box rather than as separate ellipses in E


box,
E-R
R diagrams.
diagrams
Binary relationship sets are represented in UML by just drawing a line

connecting the entity sets. The relationship set name is written adjacent
to the line.
line
The role played by an entity set in a relationship set may also be

specified by writing the role name on the line, adjacent to the entity set.
The relationship set name may alternatively be written in a box, along

with attributes of the relationship set, and the box is connected, using a
dotted line, to the line depicting
p
g the relationship
p set.

Non-binary relationships drawn using diamonds, just as in ER


diagrams

Database System Concepts - 5th Edition, Oct 5, 2006

6.65

Silberschatz, Korth and Sudarshan

UML Class Diagram Notation (Cont.)

overlapping

disjoint

*Note reversal of position in cardinality constraint depiction


*G
*Generalization
li ti can use merged
d or separate
t arrows independent
i d
d t
of disjoint/overlapping
Database System Concepts - 5th Edition, Oct 5, 2006

6.66

Silberschatz, Korth and Sudarshan

UML Class Diagrams (Contd.)


Cardinality constraints are specified in the form l..h, where l

denotes the minimum and h the maximum number of


relationships an entity can participate in.
Beware: the positioning of the constraints is exactly the reverse

of the positioning of constraints in E-R


E R diagrams.
diagrams
The constraint 0..* on the E2 side and 0..1 on the E1 side means

that each E2 entity can participate in at most one relationship,


whereas each E1 entity can participate in many relationships; in
other words, the relationship is many to one from E2 to E1.
Single
g values, such as 1 or * mayy be written on edges;
g
The

single value 1 on an edge is treated as equivalent to 1..1, while *


is equivalent to 0..*.

Database System Concepts - 5th Edition, Oct 5, 2006

6.67

Silberschatz, Korth and Sudarshan

End of Chapter 6

Database System
y
Concepts,
p , 5th Ed.
Silberschatz, Korth and Sudarshan
See www.db-book.com for conditions on re-use
Database System Concepts - 5th Edition, Oct 5, 2006

6.68

Silberschatz, Korth and Sudarshan

E-R Diagram for Exercise 2.10

Database System Concepts - 5th Edition, Oct 5, 2006

6.69

Silberschatz, Korth and Sudarshan

E-R Diagram for Exercise 2.15

Database System Concepts - 5th Edition, Oct 5, 2006

6.70

Silberschatz, Korth and Sudarshan

E-R Diagram for Exercise 2.22

Database System Concepts - 5th Edition, Oct 5, 2006

6.71

Silberschatz, Korth and Sudarshan

E-R Diagram for Exercise 2.15

Database System Concepts - 5th Edition, Oct 5, 2006

6.72

Silberschatz, Korth and Sudarshan

Existence Dependencies
If the existence of entity x depends on the existence of entity y,

then x is said to be existence dependent on y.


y
z

y is a dominant entity (in example below, loan)

x is a subordinate entity (in example below, payment)

loan

loan-payment

payment

If a loan entity
y is deleted,, then all its associated p
payment
y
entities
must be deleted also.

Database System Concepts - 5th Edition, Oct 5, 2006

6.73

Silberschatz, Korth and Sudarshan

Figure 6.8

Database System Concepts - 5th Edition, Oct 5, 2006

6.74

Silberschatz, Korth and Sudarshan

Figure 6.15

Database System Concepts - 5th Edition, Oct 5, 2006

6.75

Silberschatz, Korth and Sudarshan

Figure 6.16

Database System Concepts - 5th Edition, Oct 5, 2006

6.76

Silberschatz, Korth and Sudarshan

Figure 6.26

Database System Concepts - 5th Edition, Oct 5, 2006

6.77

Silberschatz, Korth and Sudarshan

Figure 6.27

Database System Concepts - 5th Edition, Oct 5, 2006

6.78

Silberschatz, Korth and Sudarshan

Figure 6.28

Database System Concepts - 5th Edition, Oct 5, 2006

6.79

Silberschatz, Korth and Sudarshan

Figure 6.29

Database System Concepts - 5th Edition, Oct 5, 2006

6.80

Silberschatz, Korth and Sudarshan

Figure 6.30

Database System Concepts - 5th Edition, Oct 5, 2006

6.81

Silberschatz, Korth and Sudarshan

Figure 6.31

Database System Concepts - 5th Edition, Oct 5, 2006

6.82

Silberschatz, Korth and Sudarshan

Alternative E
E--R Notations
Figure
Fi
6.24

Database System Concepts - 5th Edition, Oct 5, 2006

6.83

Silberschatz, Korth and Sudarshan

You might also like