modeling relationships farrokh alemi, ph.d. updated by janusz wojtusiak, fall 2009
TRANSCRIPT
![Page 1: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/1.jpg)
Modeling Relationships Modeling Relationships
Farrokh Alemi, Ph.D.
Updated by Janusz Wojtusiak, Fall 2009
![Page 2: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/2.jpg)
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)
![Page 3: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/3.jpg)
RelationshipsRelationships
A relationship is ALWAYS between two entities.– If you have three entities, you need at least two
relationships to link them.
![Page 4: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/4.jpg)
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."
![Page 5: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/5.jpg)
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.
![Page 6: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/6.jpg)
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.
![Page 7: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/7.jpg)
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.
![Page 8: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/8.jpg)
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…
![Page 9: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/9.jpg)
One-to-One RelationshipsOne-to-One Relationships
More examples?Justification?
![Page 10: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/10.jpg)
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.
![Page 11: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/11.jpg)
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…
![Page 12: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/12.jpg)
One-to-Many RelationshipsOne-to-Many Relationships
More examples?
![Page 13: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/13.jpg)
Some Relationships Suggest Some Relationships Suggest New EntitiesNew Entities
Hierarchical Many to many relationships
![Page 14: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/14.jpg)
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.
![Page 15: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/15.jpg)
Examples of HierarchiesExamples of Hierarchies
VehiclesOrganismsDrugsParts of a complex deviceAny other examples?
![Page 16: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/16.jpg)
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.
![Page 17: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/17.jpg)
An Example of Generalization & An Example of Generalization & SpecializationSpecialization
![Page 18: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/18.jpg)
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
![Page 19: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/19.jpg)
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.
![Page 20: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/20.jpg)
Rules for Identifying HierarchiesRules for Identifying Hierarchies
![Page 21: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/21.jpg)
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
![Page 22: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/22.jpg)
Steps for Identifying a HierarchySteps for Identifying a Hierarchy
1. Shared attributes
2. Discriminator attribute
3. Entity linkages at the super type level
![Page 23: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/23.jpg)
Step two: DiscriminatorStep two: Discriminator
![Page 24: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/24.jpg)
ExampleExample
![Page 25: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/25.jpg)
Step Three: Relations at Super Step Three: Relations at Super Entity LevelEntity Level
Reduces unnecessary relations– Simpler to read– Easier to implement
![Page 26: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/26.jpg)
Advantages of HierarchiesAdvantages of Hierarchies
Stabilize the overall model with respect to new requirements.
![Page 27: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/27.jpg)
An exampleAn example
New Requirement: “Patient of record” becomes inactive but the
system does not purge it
![Page 28: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/28.jpg)
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
![Page 29: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/29.jpg)
New Data StructureNew Data Structure
![Page 30: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/30.jpg)
Check Sub EntitiesCheck Sub Entities
The first issue is whether the sub entity is distinct form other entities
![Page 31: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/31.jpg)
Check Super EntityCheck Super Entity
Do the attributes in the super entity apply equally well to the new sub entity
![Page 32: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/32.jpg)
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
![Page 33: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/33.jpg)
HierarchiesHierarchies
Let’s work on some examples.
![Page 34: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/34.jpg)
Many to Many RelationshipsMany to Many Relationships
![Page 35: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/35.jpg)
ExampleExample
![Page 36: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/36.jpg)
Patient Clinician AssociationPatient Clinician Association
![Page 37: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/37.jpg)
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.
![Page 38: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/38.jpg)
Many-to-many relationships Many-to-many relationships
Examples:– Patient – clinician– Insurance company – patient– Nurse – bed
– Can you give more examples?
![Page 39: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/39.jpg)
Back to HierarchiesBack to HierarchiesWhat happens if we have more than one
role in a hierarchy?
![Page 40: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/40.jpg)
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.
![Page 41: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009](https://reader031.vdocuments.mx/reader031/viewer/2022013101/56649e6c5503460f94b6a63f/html5/thumbnails/41.jpg)
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.