41
Modeling Relationships Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

Embed Size (px)

Citation preview

Page 1: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

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

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

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

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

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

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

One-to-One RelationshipsOne-to-One Relationships

More examples?Justification?

Page 10: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

One-to-Many RelationshipsOne-to-Many Relationships

More examples?

Page 13: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

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

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

An Example of Generalization & An Example of Generalization & SpecializationSpecialization

Page 18: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

Rules for Identifying HierarchiesRules for Identifying Hierarchies

Page 21: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

Step two: DiscriminatorStep two: Discriminator

Page 24: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

ExampleExample

Page 25: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

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

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

New Data StructureNew Data Structure

Page 30: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

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

HierarchiesHierarchies

Let’s work on some examples.

Page 34: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

Many to Many RelationshipsMany to Many Relationships

Page 35: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

ExampleExample

Page 36: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

Patient Clinician AssociationPatient Clinician Association

Page 37: Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009

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

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

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

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

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.