Upload
jewel-howard
View
220
Download
0
Embed Size (px)
Citation preview
Modeling Relationships Modeling Relationships
Farrokh Alemi, Ph.D.
Updated by Janusz Wojtusiak, Fall 2009
Definition of RelationshipDefinition of Relationship
Relationship describes the link between two entities
Different words for the same idea – At the conceptual level (e.g. entities and their
relationships) – At the physical level (tables, data classes and
linkages)
RelationshipsRelationships
A relationship is ALWAYS between two entities.– If you have three entities, you need at least two
relationships to link them.
Relationships Are Identified Relationships Are Identified Through SentencesThrough Sentences
A sentence containing the names of the two entities and a verb phrase in between. – Verb phrases: "has," "contains," "visits,"
"prescribes," "travels with," etc. – The two entities "Patient" and "Clinician" can
be made into a sentence such as "A patient visits a clinician."
Relationships RevealedRelationships Revealed
Is one of the entities a look up table used to provide menu items for an attribute of the other entity.
Is one of the entities a subcategory to another.
Do two entities share an attribute.
Relationships DocumentationRelationships Documentation
The name of first entityThe name of second entityThe verb phrase describing the relationshipThe cardinality of the relationship
– one to one, one to many or many to many
Business justification of the relationship, particularly its cardinality.
One-to-One RelationshipsOne-to-One RelationshipsThis type of relationship often suggest that
entities have been incorrectly designedDatabase designer must identify a good
reason for using this type of relationshipOne-to-one relationships are used in
specific situations, such as:– To avoid missing data– To model hierarchies– For privacy/security reason– To break very large tables if some fields are
rarely accesses at the same time.
One-to-One RelationshipsOne-to-One Relationships
This type of relationship in realized by using a common identifiers in both entities
Employee
EmployeeIDFirstNameLastName…
EmployeeSecurity
EmployeeIDDateObtainedSecurityLevel…
One-to-One RelationshipsOne-to-One Relationships
More examples?Justification?
One-to-Many RelationshipsOne-to-Many RelationshipsThis is the most important type of relationship in
relational databasesThey are used to represent all types of relationships
in relational databases
Relational databases are about one-to-many relationships
Majority of relationships in databases are of this type.
One-to-Many RelationshipsOne-to-Many Relationships
One-to-Many relationships are represented by listing an identifier of “one” in “many”
Employee
EmployeeIDFirstNameLastName…
EmployeeAddress
AddressIDEmployeeIDDateObtainedLevel…
One-to-Many RelationshipsOne-to-Many Relationships
More examples?
Some Relationships Suggest Some Relationships Suggest New EntitiesNew Entities
Hierarchical Many to many relationships
Definition of HierarchyDefinition of Hierarchy
A collection of super and sub entities.– A super entity is the broadest definition of
several sub entities. – A sub entity is an entity that inherits its
relationship from another entity.
Examples of HierarchiesExamples of Hierarchies
VehiclesOrganismsDrugsParts of a complex deviceAny other examples?
Generalization & SpecializationGeneralization & Specialization
The process of abstracting from narrowly scoped terms into terms of broader scope is a generalization process
Starting with a general term and narrowing its scope is a specialization process.
An Example of Generalization & An Example of Generalization & SpecializationSpecialization
Hiearchy May Simplify Data Hiearchy May Simplify Data StructuresStructures
Specializations of the more general data class Person
Oftentimes, introducing a subtype hierarchy can simplify the information model
Rules for Identifying HierarchiesRules for Identifying Hierarchies
Super-type is the broadest entity, should have all the attributes that are shared across the sub-entities.
Each sub-entity should have an attribute that makes it different from other entities. – The attributes should be
mutually exclusive.
Rules for Identifying HierarchiesRules for Identifying Hierarchies
ConfusionConfusion
It may not be possible for sub types to unambiguously reside in one and only one of the subtypes specified in the hierarchy. – Refine further– If confusing, do not do it
Steps for Identifying a HierarchySteps for Identifying a Hierarchy
1. Shared attributes
2. Discriminator attribute
3. Entity linkages at the super type level
Step two: DiscriminatorStep two: Discriminator
ExampleExample
Step Three: Relations at Super Step Three: Relations at Super Entity LevelEntity Level
Reduces unnecessary relations– Simpler to read– Easier to implement
Advantages of HierarchiesAdvantages of Hierarchies
Stabilize the overall model with respect to new requirements.
An exampleAn example
New Requirement: “Patient of record” becomes inactive but the
system does not purge it
Insert a new entity in the Insert a new entity in the hierarchyhierarchy
Include the new entity in the discriminator attribute
Check that all sub entities are appropriately named
New Data StructureNew Data Structure
Check Sub EntitiesCheck Sub Entities
The first issue is whether the sub entity is distinct form other entities
Check Super EntityCheck Super Entity
Do the attributes in the super entity apply equally well to the new sub entity
Check DiscriminatorCheck Discriminator
The third issue is whether the discriminator attribute in the super-
entity applies to all sub types
The importance of good entity and attribute definitions
HierarchiesHierarchies
Let’s work on some examples.
Many to Many RelationshipsMany to Many Relationships
ExampleExample
Patient Clinician AssociationPatient Clinician Association
Association Class SimplifiesAssociation Class Simplifies
Resolve all many-to-many linkages A simpler way of capturing and tracking
relationships
In relational databases many-to-many relationships must be implemented through association classes.
Many-to-many relationships Many-to-many relationships
Examples:– Patient – clinician– Insurance company – patient– Nurse – bed
– Can you give more examples?
Back to HierarchiesBack to HierarchiesWhat happens if we have more than one
role in a hierarchy?
Self ReferralSelf Referral
A Person to Person Association A self referring relationship is found in the
same way as all relationships are found by making a sentence containing the name of the entity and a verb phrase.
Take Home LessonsTake Home Lessons
1. We saw that scenarios focus on decisions
2. Scenarios contain use cases which reveal the information exchange
3. Exchanges are used to specify fields
4. Business rules define relations
5. One-to-many is the most important type of relation.