relationships in detail

42
Relationships in Detail 1

Upload: brinly

Post on 11-Jan-2016

29 views

Category:

Documents


0 download

DESCRIPTION

Relationships in Detail. Overview. Relationships Ten different relationship types Nontransferability Relationships that seem to have attributes Rules of Normalization. Establishing a Relationship. Determine the existence of a relationship - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Relationships in Detail

1

Relationships in Detail

Page 2: Relationships in Detail

2

Relationships Ten different relationship types Nontransferability Relationships that seem to have attributes Rules of Normalization

Overview

Page 3: Relationships in Detail

3

Determine the existence of a relationship Choose a name for the relationship from both

perspectives Determine optionality Determine degree Determine nontransferability

Establishing a Relationship

Page 4: Relationships in Detail

4

Establishing the Relationship

USERMESSAGE sending

receiving

replying

Page 5: Relationships in Detail

5

Relationship Names

USERMESSAGE sent bysender

of

reply of

replied to by

sent toreceiver

of

Page 6: Relationships in Detail

6

Naming the Relationship

MESSAGE USER

receiving

A MESSAGE is received by a USER

received by

A USER is receiver of a MESSAGE

receiver of

Page 7: Relationships in Detail

7

Optionality

USERMESSAGEwritten by

author of

reply of

replied to by

received byreceiver

of

Page 8: Relationships in Detail

8

Optionality

• Must every MESSAGE be received by a USER?

No: Yes:

Yes

• Must every USER be receiver of a MESSAGE? No

MESSAGE

receiver of

USERreceived by

Page 9: Relationships in Detail

9

Mandatory 1: Mandatory m

A split intopart of

B

• Every A must be split into at least one B

• Every B must be part of exactly one A

Page 10: Relationships in Detail

10

Degree

USERwritten byauthor

of

reply of

replied to by

ATTACHMENT

with

containing

<5

received by

receiver of

MESSAGE

Page 11: Relationships in Detail

11

Degree

MESSAGE received by

receiver of

• Can a MESSAGE be received by more than one USER? Yes

• Can a USER be the receiver of more than one MESSAGE ? Yes

One: One or more:

USER

Page 12: Relationships in Detail

12

Nontransferability

USERMESSAGE written byauthor

of

reply of

replied to by

FOLDER

filed in

containing

received by

receiver of

Page 13: Relationships in Detail

13

Relationship Types1:m

(a)

(b)

(c)

(d)

Page 14: Relationships in Detail

14

PRODUCT

BUNDLE

consists of

part of

Relationship Typesm:1

Page 15: Relationships in Detail

15

Relationship Typesm:m

(e)

(f)

(g)

Page 16: Relationships in Detail

16

Relationship Typesm:m

USER

LIST

consists of

part of

Page 17: Relationships in Detail

17

Relationship Types1:1

(h)

( i)

( j )

Page 18: Relationships in Detail

18

1:1 Relationships Roles

PERSON* Name

PATIENT* Blood Type

EMPLOYEE* Job

acting as

role of

acting as

role of

Page 19: Relationships in Detail

19

1:1 Relationships Process

MESSAGEDRAFT

basis for

result of

Page 20: Relationships in Detail

20

Redundant Relationships

PERSON

TOWN

living in

of

COUNTRY

living in

located in

hometown of

location of

born in

of birth of

located in

location of

COUNTRY

PERSON

TOWN

living in

hometown of

Page 21: Relationships in Detail

21

An attribute can hide a relationship Relationship can be “downgraded” to attribute

Relationships and Attributes

ATTACHMENT* Content

ATTACHMENT TYPE* Name

with

of

ATTACHMENT* Type* Content

Page 22: Relationships in Detail

22

Easy model Fewer tables No join

Attribute Compared to Relationship

Value control List of values Other relationships

ATTACHMENT* Type* Content

ATTACHMENT* Content

ATTACHMENT TYPE* Name

with

of

Page 23: Relationships in Detail

JOBEMPLOYEE* Id

BADGE

NATIONALITY

ADDRESS

NAME

SALARY

GENDER

TEAM

Attribute or Entity

23

Page 24: Relationships in Detail

24

There is no such thing as a foreign key attribute

Usually, the attribute name should not contain an entity name

Attribute Compared to Relationship

MESSAGE* Message Id* Text* Folder Name

FOLDER* Name

placed in

containing

Page 25: Relationships in Detail

25

Relationship Compared to Attribute

MESSAGE* Addressee

USER

MESSAGE USER

addressee of

addressed to

MESSAGEo Addressee

USER

addressee of

addressed to

Page 26: Relationships in Detail

26

PRODUCT * Code * Name

CUSTOMER* Id* Name

bought by

buyer of

m:m Relationships May Hide Something

Page 27: Relationships in Detail

27

?

Quantity

PRODUCTCUSTOMER

* Id* Name

* Code* Namebought by

buyer of

Quantity Is Attribute of ...

PRODUCTCUSTOMER

* Id* Name

* Code* Name

buyer of

?

Quantity

bought by

Page 28: Relationships in Detail

28

PRODUCTCUSTOMER

* Id* Name

* Code* Namebought by

buyer of

Attribute of Relationship ?

Quantity

Page 29: Relationships in Detail

29

CUSTOMER* Id* Name

PRODUCT* Code* Name

ORDER

with

with

for

of

New Entity ORDER

*Quantity Sold

Name

SanchezLowitchYomita

CUSTOMERS

Id

1 2 3 4

PRODUCTS

Code

12 3 4

Name

JeansShirtTie

ORDERS

Ctr_id

1123

Pdt_code

2 3 2

Quantity_sold

221

Page 30: Relationships in Detail

30

ORDER* Id* Date

with

with

for

of

CUSTOMER* Id* Name

PRODUCT* Code* Name

Multiple PRODUCTS for an ORDER

Quantity?

Page 31: Relationships in Detail

31

for for

ORDER ITEM

with

with

of

with

CUSTOMER* Id* Name

PRODUCT* Code* Name

ORDER HEADER* Id* Date

Another New Entity: ORDER ITEM

*Quantity Sold

Page 32: Relationships in Detail

CUSTOMERS

1 2

SanchezLowitchYomita

Id Name ORDER_HEADERS

1 2

Id Ctr_id

1 2

Date_ordered

25-MAY-1999 25-MAY-199925-MAY-1999

ORDER_ITEMS

1 2

Ohd_id Pdt_code

2 2

Quantity_sold

221

PRODUCTS

Code

12 3 4

Name

JeansShirtTie

Tables

32

Page 33: Relationships in Detail

33

Create new intersection entity Create two m:1 relationships, derive

optionality Remove m:m relationship

Resolving m:m Relationship

A

B

xxx

yyy

A/B COMBINATION

A

B

of

of

in

in

Page 34: Relationships in Detail

34

Create new intersection entity Create two m:1 relationships, derive optionality Remove m:m relationship

Resolving m:m Relationship

xxx

yyy

A

B

A/B COMBINATIONof

of

with

with

Page 35: Relationships in Detail

35

PERSON

CUSTOMER TYPE

classifiedas

classification of

external

Resolving m:1 Relationship

internal

Page 36: Relationships in Detail

36

Resolving m:1 Relationship

PERSON CUSTOMER TYPE

internal

external

in

CLASSIFICATION

with

for with

Page 37: Relationships in Detail

37

Normalization RulesNormal Form Rule Description

First Normal Form All attributes are single valued.

Second Normal Form (2NF) An attribute must be dependent upon entity’s entire unique identifier.

Third Normal Form (3NF) No non-UID attribute can be dependent on another non-UID attribute.

“A normalized entity-relationship data model automatically translates into a normalized relational database design”

“Third normal form is the generally accepted goal for a database design that eliminated redundancy”

Page 38: Relationships in Detail

38

First Normal Form in Data Modeling

RECEIVED MESSAGE# Receive Dateo Subjecto Text

received by

receiver of

All attributes must be single-valued.

USER# Name* Person Name* Message Receive Dateo Message Subjecto MessageText

USER# Name* Person Name

Page 39: Relationships in Detail

39

Second Normal Form in Data Modeling

MESSAGE# Ido Text

includingincluded

in

An attribute must be dependent upon its entity’s entire unique identifier.

including

included in

RECEIVED MESSAGE# User Name * Receive Date

RECEIVED MESSAGE# User Name * Receive Date* Subject

MESSAGE# Ido Text* Subject

Page 40: Relationships in Detail

40

Third Normal Form in Data ModelingUSER

# Name* Person Name* Password* Server Id * Server Name

assigned to

distribute mail

to

MAIL SERVER# Id* Name

USER# Name * Person Name * Password

No non-UID attribute can be dependent upon another non-UID attribute.

Page 41: Relationships in Detail

41

Relationships express how entities are connected. Initially relationships often seem to be of type m:m. Finally relationships are most often of type m:1. Relationships can be resolved into:

Two new relationships One intersection entity

Third Normal form is generally accepted standard.

Summary

Page 42: Relationships in Detail

42

Read the Relationship Find a Context Name the Intersection Entity Receipt Moonlight P&O Price List EMail Holiday

Practices