Transformation of E/R Diagram to Relation

17

description

Transformation of E/R Diagram to Relation. Transformation of E/R Diagram to Relation. Primary keys allow entity sets and relationship sets to be expressed uniformly as relations E/R diagram  collection of tables For each entity set and each relationship set there is a unique table. - PowerPoint PPT Presentation

Transcript of Transformation of E/R Diagram to Relation

Page 1: Transformation of E/R Diagram to Relation
Page 2: Transformation of E/R Diagram to Relation

Primary keys allow entity sets and relationship sets to be expressed uniformly as relations

E/R diagram collection of tables For each entity set and each relationship

set there is a unique table

04/24/23CSCE 520 2

Page 3: Transformation of E/R Diagram to Relation

Entity set: becomes a relation with the attributes of the entity set

Relationship: becomes a relation with attributes:◦ Key of connected entity sets◦ Attributes of the relationship

04/24/23CSCE 520 3

Page 4: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 4

Example E/R Diagram

Dog

Name Breed

Age

License #

Phone

Weight

Name

Name

Phone

Address

Owns

Owner

Kennel

Pays

Boards

Amount

Page 5: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 5

Entity Set to Relation

Dog

Name Breed

Age

Weight Dog(Name,Breed,Age,Weight)

Page 6: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 6

Entity Set to Relation

OwnerKennel Pays

AmountName NameAddress

Pays(Kennel. Name,Owner.Name,Amount,Date)

Phone

Date

Page 7: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 7

Combining Relations: Many-One

OwnerKennel Pays

AmountName NameAddress

Combine relation for entity of “many” side (Owner) with relationship set, i.e., Owner’s-favorite(Name,Phone,FavoriteKennel.Name)

Favorite

Phone

Date

Page 8: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 8

Combining Relations: Many-Many

OwnerKennel Pays

Name NameAddress

Combining Owner with pays:Owner(Kennel.Name,Owner.Name,Phone)

Phone

Page 9: Transformation of E/R Diagram to Relation

Kennel Name

Owner Name

Owner Phone

White Oak Mary 890-4421Little Creek Mary 890-4421White Oak Viki 987-4456White Oak Joe 334-2234

04/24/23 CSCE 520 9

Redundancy

Page 10: Transformation of E/R Diagram to Relation

Relation for a weak entity set must include attributes for its complete key (including those that belong to other entities) as well as its own, non-key attributes

Supporting relationship is redundant and does not yield a relation

04/24/23CSCE 520 10

Page 11: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 11

Dog

Name Breed

Age OwnerOwns

Name

Phone

Owner(Owner.Name, Phone)Dog(Dog.Name,Owner.Name, Age,Breed)Owns(Dog.Name,Owner.Name1,Owner.Name2)

Must be the sameAlready in DogRedundant!

Page 12: Transformation of E/R Diagram to Relation

Three approaches:1. Object-oriented: each entity belongs to exactly one

class. Create a relation for each class with all its attributes.

2. E/R style: create one relation for each subclass with only the key attributes and the attributes of the subclass. Entity is represented in all relations to whose subclass entity set it belongs.

3. Null values: create on relation with all attributes. Entities have null values in attributes that do not belong to them.

04/24/23CSCE 520 12

Page 13: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 13

Example Subclass

Dog

Name Breed

Show-Dog Rank

ISA

Page 14: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 14

Object-Oriented Approach

Name BreedBuddy Mix

Name Breed RankPepper Germanshepherd 1st

Dog

Show dog

Page 15: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 15

Name BreedPepper GermanshepherdBuddy Mix

Name RankPepper 1st

Dog

Show dog

Page 16: Transformation of E/R Diagram to Relation

04/24/23CSCE 520 16

Null Values

Name Breed RankBuddy Mix NULLPepper Germanshepherd 1st

Dog

Page 17: Transformation of E/R Diagram to Relation

Object-Oriented: good for queries like “find all G.S. dogs that ranked 2nd or above”.

E/R: good for “find all G.S. dogs (regardless of being a show dog or not)

Null values: may save space, but not good if too many attributes with null values.

04/24/23CSCE 520 17