Relationship Types Multiple Relationships You can have multiple

  • Slides: 10
Download presentation
Relationship Types

Relationship Types

Multiple Relationships You can have multiple relationships between the same entity sets Pokémon belongs

Multiple Relationships You can have multiple relationships between the same entity sets Pokémon belongs fought Trainer

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship.

Attributes on Relationships Sometimes it is useful to attach an attribute to a relationship. Think of this attribute as a property of tuples in the relationship set. caught by Pokémon Pokéball Type Location Trainer

Equivalent Diagram Without Attributes on Relationships caught by Pokémon Capture Pokéball Type Location Trainer

Equivalent Diagram Without Attributes on Relationships caught by Pokémon Capture Pokéball Type Location Trainer

Roles Sometimes an entity set appears multiple times in a relationship. The edges need

Roles Sometimes an entity set appears multiple times in a relationship. The edges need to be labeled with a role, to disambiguate. Trainer Attacker Defender battle

Subclasses A subclass is a special case of an entity set with fewer entries

Subclasses A subclass is a special case of an entity set with fewer entries than the original, but more properties. ◦ A property is an attribute or relationship. ◦ No multiple inheritance allowed! name type Pokémon Example: "Wild. Pokémon" is a subclass of "Pokémon". ◦ Not every Pokémon is a Wild. Pokémon (some have been caught by Trainers). ◦ Wild. Pokémon have properties in addition to normal Pokémon (such as Location where they are found or propensity to run away). The "isa" triangle points at from the subclass to the superclass. isa Wild Pokémon Location found run_away

E/R Subclasses Versus Object-Oriented Subclasses In OO, objects each belong to one class only.

E/R Subclasses Versus Object-Oriented Subclasses In OO, objects each belong to one class only. ◦ Subclasses inherit from superclasses In E/R, entities have representatives in all subclasses to which they belong ◦ An entity in a subclass, must have an entity in all of its superclasses. Example: ◦ To represent a wild Abra, you need an entity in the "Wild. Pokémon" entity set (which has its "found" and "run_away" properties) and in the "Pokémon" entity set (which has its name and type properties). More details later on.

Keys A key is a set of attributes for one entity set such that

Keys A key is a set of attributes for one entity set such that no two entities in this set agree on all attributes of the key. ◦ It is allowed for two entities to agree on some, but not all, of the key attributes. You must designate a key for every entity set (underline the key attributes). In a "isa" hierarchy, only the root entity set (most super of superclasses) has a key, and that key must serve as the key for all entities in the hierarchy. Location Box Pokémon Bill's PC

Weak Entity Sets Occasionally, entities of an entity set need “help” to identify them

Weak Entity Sets Occasionally, entities of an entity set need “help” to identify them uniquely (they don't have a key). Entity set E is said to be weak if in order to identify entities of E uniquely, we need to follow one or more many-one relationships from E and include the key of the related entities from the connected entity sets.

Example Two entity sets: ◦ Pokémon (name, position) ◦ Status (effect, duration) The entity

Example Two entity sets: ◦ Pokémon (name, position) ◦ Status (effect, duration) The entity set "Status" requires a lookup of the many-to-exactly one relationship "has" to get all of its keys. position name has Pokémon ◦ To specify a unique entity in "Status" you need the "effect" and the "position". The weak entity set and the supporting many-to-exactly-one relationships should be doubled outlined. Status effect duration