Primary keys allow entity sets and relationship sets to be expressed uniformly as relations E/R...

17

Transcript of Primary keys allow entity sets and relationship sets to be expressed uniformly as relations E/R...

Page 1: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.
Page 2: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

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/20/23CSCE 520 2

Page 3: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

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/20/23CSCE 520 3

Page 4: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/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: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 5

Entity Set to Relation

Dog

Name Breed

Age

WeightDog(Name,Breed,Age,Weight)

Page 6: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 6

Entity Set to Relation

OwnerKennel Pays

AmountNameName

Address

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

Phone

Date

Page 7: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 7

Combining Relations: Many-One

OwnerKennel Pays

AmountNameName

Address

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: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 8

Combining Relations: Many-Many

OwnerKennel Pays

NameName

Address

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

Phone

Page 9: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

Kennel Name

Owner Name

Owner Phone

White Oak Mary 890-4421

Little Creek Mary 890-4421

White Oak Viki 987-4456

White Oak Joe 334-2234

04/20/23 CSCE 520 9

Redundancy

Page 10: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

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/20/23CSCE 520 10

Page 11: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/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: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

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/20/23CSCE 520 12

Page 13: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 13

Example Subclass

Dog

Name Breed

Show-DogRank

ISA

Page 14: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 14

Object-Oriented Approach

Name Breed

Buddy Mix

Name Breed Rank

Pepper Germanshepherd 1st

Dog

Show dog

Page 15: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 15

Name Breed

Pepper Germanshepherd

Buddy Mix

Name Rank

Pepper 1st

Dog

Show dog

Page 16: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

04/20/23CSCE 520 16

Null Values

Name Breed Rank

Buddy Mix NULL

Pepper Germanshepherd 1st

Dog

Page 17: Primary keys allow entity sets and relationship sets to be expressed uniformly as relations  E/R diagram  collection of tables  For each entity set.

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/20/23CSCE 520 17