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 11/15/2015CSCE 5202
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 11/15/2015CSCE 5203
11/15/2015CSCE 5204 Example E/R Diagram Dog Name Breed Age License # Phone Weight Name Phone Address Owns Owner Kennel Pays Boards Amount
11/15/2015CSCE 5205 Entity Set to Relation Dog Name Breed Age Weight Dog(Name,Breed,Age,Weight)
11/15/2015CSCE 5206 Entity Set to Relation OwnerKennel Pays AmountName Address Pays(Kennel. Name,Owner.Name,Amount,Date) Phone Date
11/15/2015CSCE 5207 Combining Relations: Many-One OwnerKennel Pays Amount Name Address Combine relation for entity of “many” side (Owner) with relationship set, i.e., Owner’s-favorite(Name,Phone,FavoriteKennel.Name) Favorite Phone Date
11/15/2015CSCE 5208 Combining Relations: Many-Many OwnerKennel Pays Name Address Combining Owner with pays: Owner(Kennel.Name,Owner.Name,Phone) Phone
Kennel Name Owner Name Owner Phone White OakMary Little CreekMary White OakViki White OakJoe /15/2015CSCE 5209 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 11/15/2015CSCE 52010
11/15/2015CSCE Dog Name Breed Age Owner Owns Name Phone Owner(Owner.Name, Phone) Dog(Dog.Name,Owner.Name, Age,Breed) Owns(Dog.Name,Owner.Name1,Owner.Name2) Must be the same Already in Dog Redundant!
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. 11/15/2015CSCE 52012
11/15/2015CSCE Example Subclass Dog NameBreed Show-Dog Rank ISA
11/15/2015CSCE Object-Oriented Approach NameBreed BuddyMix NameBreedRank PepperGermanshepherd1st Dog Show dog
11/15/2015CSCE NameBreed PepperGermanshepherd BuddyMix NameRank Pepper1st Dog Show dog
11/15/2015CSCE Null Values NameBreedRank BuddyMixNULL PepperGermanshepherd1st Dog
Object-Oriented: good for queries like “find all G.S. dogs that ranked 2 nd 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. 11/15/2015CSCE 52017