Presentation is loading. Please wait.

Presentation is loading. Please wait.

ER to Schema.

Similar presentations


Presentation on theme: "ER to Schema."— Presentation transcript:

1 ER to Schema

2 From E/R Diagrams to Relations
Entity Set -> Relation. Attributes -> Attributes. Relationships -> Relations whose attributes are only: The keys of the connected entity sets. Attributes of the relationship itself.

3 Entity Set -> Relation
Pokémon(name, species) name Pokémon species

4 Relationship -> Relation
Pokémon(name, species) Trainer(name) Belongs(p_name, t_name) Fought(attacker, defender) name name belongs Trainer defender Pokémon attacker species fought

5 Combining Relations You can "combine" relations together:
Pokémon(name, species) + Belongs(p_name, t_name) becomes: Pokémon(name, species, trainer) Rule: You can combine in the relationship sets with an entity set, if that set is the "many" part of a many- to-one relationship.

6 Can we combine Trainers and Fought?
1. No, cyclical relationships sets can't be merged 2. Yes, yielding Trainer(name, badges, defender) 3. No, the "fought" relation is not many- to-one 4. The Pokémon references are silly name badges Trainer defender attacker fought

7 Many-to-Many Combination
Combining "Fought" with "Trainers" leads to redundancy. Trainers Fought Combined name badges Ash 8 Brock 2 Misty 3 Oak attacker defender Ash Brock Misty name badges defender Ash 8 Brock 2 Misty 3 NULL Oak Redundancy! See badges.

8 Weak Entity Sets to Relations
Relation for a weak entity set must include attributes for its complete key (including those belonging to other entity sets), as well as its own, non-key attributes. A supporting relationship is redundant and yields no relation (unless it has attributes). Relations: Pokémon(name, position) Status(effect, duration, position) Has(effect, position) Redundant position name has Pokémon Status effect duration

9 Subclasses: 3 methods Nulls: One relation; entities have NULL in attributes that don't belong to them Object-oriented: One relation per subset of subclasses, with all relevant attributes E/R style: One relation for each subclass: Key attributes Attributes of that subclass

10 Example: Nulls isa isa name type Pokémon name type owner run_away Abra
psychic NULL True Pikachu electric Red False Onix rock Brock Mew Pokémon isa isa owner Caught Pokémon Wild Pokémon run_away

11 Example: Object-oriented
Pokémon name type name type Mew psychic Pokémon Wild Pokémon name type run_away Abra psychic True isa isa Caught Pokémon name type owner Onix rock Brock Caught and Wild Pokémon owner Caught Pokémon Wild Pokémon run_away name type owner run_away Pikachu electric Red False

12 Example: E/R style isa isa name type Pokémon Caught Pokémon name type
Abra psychic Pikachu electric Onix rock Mew name owner Onix Brock Pikachu Red Pokémon isa isa Wild Pokémon name run_away Abra True Pikachu False owner Caught Pokémon Wild Pokémon run_away

13 Which method to handle subclasses is best?
1. Object-oriented 2. Nulls 3. E/R style 4. Depends


Download ppt "ER to Schema."

Similar presentations


Ads by Google