Chapter 2: Entity-Relationship Model Entity Sets Entity Sets ...
Primary keys allow entity sets and relationship sets to be expressed uniformly as relations E/R...
-
Upload
lewis-conley -
Category
Documents
-
view
234 -
download
3
Transcript of Primary keys allow entity sets and relationship sets to be expressed uniformly as relations E/R...
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
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
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
04/20/23CSCE 520 5
Entity Set to Relation
Dog
Name Breed
Age
WeightDog(Name,Breed,Age,Weight)
04/20/23CSCE 520 6
Entity Set to Relation
OwnerKennel Pays
AmountNameName
Address
Pays(Kennel. Name,Owner.Name,Amount,Date)
Phone
Date
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
04/20/23CSCE 520 8
Combining Relations: Many-Many
OwnerKennel Pays
NameName
Address
Combining Owner with pays:Owner(Kennel.Name,Owner.Name,Phone)
Phone
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
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
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!
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
04/20/23CSCE 520 13
Example Subclass
Dog
Name Breed
Show-DogRank
ISA
04/20/23CSCE 520 14
Object-Oriented Approach
Name Breed
Buddy Mix
Name Breed Rank
Pepper Germanshepherd 1st
Dog
Show dog
04/20/23CSCE 520 15
Name Breed
Pepper Germanshepherd
Buddy Mix
Name Rank
Pepper 1st
Dog
Show dog
04/20/23CSCE 520 16
Null Values
Name Breed Rank
Buddy Mix NULL
Pepper Germanshepherd 1st
Dog
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