19
Transforming ER diagrams into relations Refers to Old Questions (Basic Idea of Golf Tour ERD) I) Map Regular Entities to Relations Example (1) Player - Composite Attribute: Use only their simple, component attributes Player Playe rID FName LName Gende r DOB Heigh t Weigh t Nationa lity 1 Player PlayerNa FName LName DOB Gende Heigh Weigh Nationa Player

Drawing eer examplesupdated_includingcrow_sfoot

Embed Size (px)

Citation preview

Page 1: Drawing eer examplesupdated_includingcrow_sfoot

Transforming ER diagrams into relationsRefers to Old Questions (Basic Idea of Golf Tour ERD)

I) Map Regular Entities to Relations

Example (1) Player- Composite Attribute: Use only their simple, component attributes

Player

PlayerID FName LName Gender DOB Height Weight Nationality

(Or)

1

PlayerPlayerName

FName

LName

DOB

Gender

Height

WeightNationality

PlayerID

Page 2: Drawing eer examplesupdated_includingcrow_sfoot

- Multi-valued Attribute – Become an separate relation with a foreign key taken

from the superior entity.

PlayerID

FName LName Gender

DOB Height

Weight NationalityID

2

PlayerPlayerNameLName

DOB

Gender

Height

WeightNationality

FNamePlayerID

NationalityI

D

Nation

Page 3: Drawing eer examplesupdated_includingcrow_sfoot

Example (2) Tournament

Composite Attribute: Use only their simple component attributes.

TournamentID

TournamentName Country

3

TournamentID Tournament

TournamentName

Country

Page 4: Drawing eer examplesupdated_includingcrow_sfoot

II) Map Weak Entities

- Becomes a separate relation with a foreign key taken from the superior entity.

4

ScoreBoard

MatchID Match

MatchName

Duration

Hole

Par

Result

includes

ScoreBoardID

MatchID

Page 5: Drawing eer examplesupdated_includingcrow_sfoot

By using Crow’s Foot Notation,

(line ဆြ�ဲတဲ႔အခါ table တစ္ခုရဲ႕ primary key ဟာ အျခား table မွာForeign Key အေအနန႔ဲဘဲသံု�းထားရင္ Dotted Line န႔ဲဆြ�ဲပါ။ Primary Key အေအနန႔ဲျပန္သံု �းရင္ Solid line န႔ဲဆြ�ဲပါ။)

Match

MatchID

MatchName Duration

ScoreBoard

ScoreBoardID Hole Par Result MatchID

III) Map Binary Relationships

- One to Many : Primary key on the one side becomes a foreign key on the many

sides

5

has

MatchPK MatchID

MatchName

Duration ScoreBoardPK ScoreBoardID

FK1 MatchID

Hole

Par

Result

Page 6: Drawing eer examplesupdated_includingcrow_sfoot

- Many to Many: Create a new relation with the primary keys of the two entities

as its primary key.

- One to One – Primary key on the mandatory side becomes a foreign key on the

optional side.

One to Many Example

Tournament

TournamentI

D

TournamentNam

e

Location

Match

MatchID MatchName Duration TournamentID

One to One Example

6

Tournament Match

MatchID TournamentIDTournamentID

contains

Match Plays at Golf Course

Page 7: Drawing eer examplesupdated_includingcrow_sfoot

Match

MatchID MatchNam

e

Duration

GolfCourse

GolfCourseID Name Location MatchID

Many to Many Example

7

MatchID Name Location MatchID

Player Match Play_Match

PlayerID MatchID

contains

contains

ုSွolid လိ�င္ုးန႔ဲဆြ�ဲပါ. PlayerID ကိ� PlayerMatch မွာ Primary Key

အေအနန႔ဲသံု�းလိ�႔ အလားတူMatchID ပါ

PlayerPK PlayerID

FName

LName

Gender

DOB

Height

Weight

Nationality

PlayerMatchPK, FK1

PK,FK2

PlayerID

MatchID

MatchPK MatchID

MatchName

Duration

Page 8: Drawing eer examplesupdated_includingcrow_sfoot

(Crow’s Foot Notation မွာ line ဆြ�ဲတဲ႔အခါ table တစ္ခုရဲ႕ primary key ဟာ အျခားtable မွာ Primarky Key အေုတြတအျဖစ္ုျပန္သံု �းထားရင္ Solid Line န႔ဲဆြ�ဲပါ။) Player

PlayerID FName LName Gender DOB Height Weight Nationality

Play_Match

PlayerID MatchID

Match

MatchID MatchNam

e

Duration

IV) Map Associative Entity

- Identifier Not Assigned: Default Primary key for the association relation is the

primary keys of the two entities.

- Identifier Assigned: It is natural to end users. Default identifier may not be

unique.

Associative Entity Example (Identifier Not Assigned)

8

Player Match

PlayerID MatchID

Active

Player

Status

Page 9: Drawing eer examplesupdated_includingcrow_sfoot

Player

PlayerID FName LName Gender DOB Height Weight Nationality

Active_Player

PlayerID MatchID Status

Match

MatchID MatchNam

e

Duration

*For Identifer assigned, put ActivePlayerID in Active_Player Entity.

V) Map Ternary (and n-ary) Relationships

- One relation for each entity and one for the associative entity.

Ternary relationship with associative entity

9

Match Venue

MatchID VenueID

Play_Match

Referee

Page 10: Drawing eer examplesupdated_includingcrow_sfoot

Match

MatchID MatchNam

e

Duration

Referee

RefereeID FirstName LastName Nationality

Play_Match

MatchID RefereeID VenueID Status

Venue

VenueID Name Location

VI) Supertype/ Subtype Relationships

Super types

- has distinct subtypes

Subtypes

- share some attributes

- have some unshared attributes

- carry attributes from the parent type

- Also member of the supertype

Constraints in Super type/Subtype

10

RefereeID

Page 11: Drawing eer examplesupdated_includingcrow_sfoot

- Disjoint (d)

- Overlap (o)

Participation Constraint

i) Total (member must belongs to supertype)

ii) Partial (member does not have to belongs to subtype)

Categorization

- Union (u)

- Subtypes can have more than one parent type

- A category class is associated with two distinct supertypes

- Selective Parentage (‘Inheritance’)

- depends on parent

- Total and Partial Paticipation

-Total participation can be represented as specialization/generalization

Disjoint Example

11

Player

Teen Adult

d

PlayerID

DOB

Player is Supertype

Teen and Adult are Subtypes

Constraints in Super type/Subtype (disjoint)

Total participation (Teen or Player must belongs to

Player)

Page 12: Drawing eer examplesupdated_includingcrow_sfoot

Mapping to Schema

There are three options to map relational schema.

i) Map super and subtypes to a single table

- include all attributes for all subtypes

- This option is for specialization whose subclasses are DISJOINT

ii) Map each subtype to a table

- include attributes of supertype in each table

- This option works well only for disjoint and total constraints.

iii) Map supertype to a table and each subtype to a table

- do not repeat attributes in any table

- This option works for any constraints: disjoint or overlapping; total or partial.

*Choice will depend on data

By using option 1, Map super and subtypes to a single table

Player

PlayerID

FName LName Gender DOB Height

Weight Nationality Player

Type

Age School Career

12

PlayerID School PlayerID CareerAge Age

Page 13: Drawing eer examplesupdated_includingcrow_sfoot

By using option 2, Map super and subtypes to a single table

Player

PlayerID FName LName

Teen

PlayerID Gender DOB Height Weight Nationality Age School

Adult

PlayerID Gender DOB Height Weight Nationality Age career

By using option 3, Map supertype to a table and each subtype to a table

Player

PlayerID

FName LName

Gender DOB Height Weight Nationality

Teen

PlayerID Age School

13

Page 14: Drawing eer examplesupdated_includingcrow_sfoot

Adult

PlayerID Age Career

Overlap Example

By using option 3, Map supertype to a table and each subtype to a table

Player

PlayerID

FName LName

Gender DOB Height Weight Nationality

LocalPlayer

PlayerID

Location

14

Player

LocalPlayer

o

PlayerID

IDLocation Nation

InternationalPlayer

ID

Page 15: Drawing eer examplesupdated_includingcrow_sfoot

InternationalPlayer

PlayerID Nation

Union Example

LocalPlayer

ID Location PlayerID

InternationalPlayer

ID Nation PlayerID

PlayerID

FName LName Gender DOB Height Weight Nationality PlayerType

Age

School

15

LocalPlayer InternationalPlayer

Player

u