Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "Modeling Relationships Farrokh Alemi, Ph.D. Updated by Janusz Wojtusiak, Fall 2009."— Presentation transcript:

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

2 Definition 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)

3 Relationships A relationship is ALWAYS between two entities. – If you have three entities, you need at least two relationships to link them.

4 Relationships Are Identified Through 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."

5 Relationships 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.

6 Relationships Documentation The name of first entity The name of second entity The verb phrase describing the relationship The cardinality of the relationship – one to one, one to many or many to many Business justification of the relationship, particularly its cardinality.

7 One-to-One Relationships This type of relationship often suggest that entities have been incorrectly designed Database designer must identify a good reason for using this type of relationship One-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.

8 One-to-One Relationships This type of relationship in realized by using a common identifiers in both entities Employee EmployeeID FirstName LastName … EmployeeSecurity EmployeeID DateObtained SecurityLevel …

9 One-to-One Relationships More examples? Justification?

10 One-to-Many Relationships This is the most important type of relationship in relational databases They 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.

11 One-to-Many Relationships One-to-Many relationships are represented by listing an identifier of “one” in “many” Employee EmployeeID FirstName LastName … EmployeeAddress AddressID EmployeeID DateObtained Level …

12 One-to-Many Relationships More examples?

13 Some Relationships Suggest New Entities Hierarchical Many to many relationships

14 Definition 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.

15 Examples of Hierarchies Vehicles Organisms Drugs Parts of a complex device Any other examples?

16 Generalization & 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.

17 An Example of Generalization & Specialization

18 Hiearchy May Simplify Data Structures Specializations of the more general data class Person Oftentimes, introducing a subtype hierarchy can simplify the information model

19 Rules 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.

20 Rules for Identifying Hierarchies

21 Confusion 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

22 Steps for Identifying a Hierarchy 1. Shared attributes 2. Discriminator attribute 3. Entity linkages at the super type level

23 Step two: Discriminator

24 Example

25 Step Three: Relations at Super Entity Level Reduces unnecessary relations – Simpler to read – Easier to implement

26 Advantages of Hierarchies Stabilize the overall model with respect to new requirements.

27 An example New Requirement: “Patient of record” becomes inactive but the system does not purge it

28 Insert a new entity in the hierarchy Include the new entity in the discriminator attribute Check that all sub entities are appropriately named

29 New Data Structure

30 Check Sub Entities The first issue is whether the sub entity is distinct form other entities

31 Check Super Entity Do the attributes in the super entity apply equally well to the new sub entity

32 Check 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

33 Hierarchies Let’s work on some examples.

34 Many to Many Relationships

35 Example

36 Patient Clinician Association

37 Association 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.

38 Many-to-many relationships Examples: – Patient – clinician – Insurance company – patient – Nurse – bed – Can you give more examples?

39 Back to Hierarchies What happens if we have more than one role in a hierarchy?

40 Self 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.

41 Take 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.


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

Similar presentations


Ads by Google