+ All Categories
Home > Documents > Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see...

Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see...

Date post: 30-Dec-2015
Category:
Upload: bernard-martin
View: 213 times
Download: 0 times
Share this document with a friend
21
Unary Relationships Unary Relationships
Transcript
Page 1: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

Unary RelationshipsUnary Relationships

Page 2: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

On the JobOn the Job

• Is this a legitimate design?Is this a legitimate design?• Do you see problems with it?Do you see problems with it?

Supervisor Workermanages

is managed by

Page 3: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

The FamilyThe Family

• Is this a legitimate design?Is this a legitimate design?• Do you see problems with it?Do you see problems with it?

Husband Wife

Child

marries

is married to

fathers

is child of bears

is child of

Page 4: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

Complicated RelationshipsComplicated RelationshipsAmong People*Among People*

• Workers have supervisors, who also have Workers have supervisors, who also have supervisorssupervisors

• Men and women can marry more than onceMen and women can marry more than once• Children born out of wedlockChildren born out of wedlock• Half-brothers and -sisters Half-brothers and -sisters

• What design will accommodate all of these?What design will accommodate all of these?

* Not intended as a comment on social mores.* Not intended as a comment on social mores.

Page 5: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

Relating an Entity to ItselfRelating an Entity to Itself

• An entity can be related to itself.An entity can be related to itself.• Called a “unary” or “recursive” relationshipCalled a “unary” or “recursive” relationship• Where do you put the foreign keys?Where do you put the foreign keys?

Employee

supervises

supervised by

Person

related to

is relative of

Page 6: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

Unary 1:MUnary 1:M

• Recursive foreign key placed in entityRecursive foreign key placed in entity• Name of FK must be different from name of PKName of FK must be different from name of PK• Second instance of entity required in queries Second instance of entity required in queries

and relationships screenand relationships screen

Employee

EmployeeID

LastNameFirstNameMidNameSupervisorID [FK]

supervises

supervised by

Page 7: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

Unary 1:1 or M:MUnary 1:1 or M:M

• Associative entity requiredAssociative entity required

Person

PersonID

LastNameFirstNameMidName

Relationship [As]

FromPerson [FK]ToPerson [FK]RelationshipType [FK]

FromDateToDate

is source of

contains

is targetof

refers to

InterpersRelat

RelationshipType

RelationshipNameRelationshipDesc

describes

is of type

Page 8: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

Unary 1:1 or M:MUnary 1:1 or M:M

• Name of FKs must be different in associative Name of FKs must be different in associative entityentity

• Second instance of entity required in queries Second instance of entity required in queries and relationships screenand relationships screen

Page 9: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

Common Uses of Common Uses of Unary RelationshipsUnary Relationships

• PeoplePeople– sometimes supertype/subtype required to sometimes supertype/subtype required to

fully document relationshipfully document relationship

• Bill of MaterialsBill of Materials– products composed of other productsproducts composed of other products

• Political GeographyPolitical Geography– Precincts within cities within counties within Precincts within cities within counties within

states within countries within continentsstates within countries within continents

Page 10: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

More about the 1:1 or M:M More about the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• Interpersonal relationships are often Interpersonal relationships are often two-way, with the reciprocal relationship two-way, with the reciprocal relationship sometimes having a different namesometimes having a different name– Parent-childParent-child– Sibling-siblingSibling-sibling– Spouse-spouseSpouse-spouse– Supervisor-workerSupervisor-worker– Employer-employeeEmployer-employee

Page 11: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

More about the 1:1 or M:M More about the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• In general, it is better to have only one In general, it is better to have only one record for a given relationshiprecord for a given relationship– Do not haveDo not have

• One record where person A is “child of” BOne record where person A is “child of” B• A second record where B is “parent of” AA second record where B is “parent of” A

– InsteadInstead• A single record that records both directions of A single record that records both directions of

the relationshipthe relationship

• Requires that there be the ability to Requires that there be the ability to indicate the reciprocal of a relationshipindicate the reciprocal of a relationship

Page 12: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

A “Relationship Type” table is A “Relationship Type” table is created to hold both “forward” created to hold both “forward” and “reciprocal” terms for the and “reciprocal” terms for the relationshiprelationship

Page 13: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• Only one entry per pair (if 1:1)Only one entry per pair (if 1:1)

Page 14: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• Carefully define the directionalityCarefully define the directionality– In these examplesIn these examples

• [second person] is the [relationship] of [first [second person] is the [relationship] of [first person]person]

• [first person] is the [reciprocal] of [second [first person] is the [reciprocal] of [second person]person]

Page 15: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• Create a view for one direction that includes Create a view for one direction that includes PersonID, Name, and Relationship with Other PersonPersonID, Name, and Relationship with Other Person

Page 16: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• Expression that returns the Expression that returns the “Relationship with Other Person”“Relationship with Other Person”

Relationship: [tblRelationshipType]![RelationshipType] & Relationship: [tblRelationshipType]![RelationshipType] & " of " & fnNameFirstLast([tblPerson_1]![FirstName], " of " & fnNameFirstLast([tblPerson_1]![FirstName], [tblPerson_1]![MidName],[tblPerson_1]![LastName])[tblPerson_1]![MidName],[tblPerson_1]![LastName])

Page 17: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• Create a view for the reciprocal directionCreate a view for the reciprocal direction

Page 18: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

Data entry form allows for the Data entry form allows for the specification of relationship in specification of relationship in one directionone direction

Page 19: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

Already-entered reciprocal Already-entered reciprocal relationships are shown to relationships are shown to discourage duplicate entriesdiscourage duplicate entries

Page 20: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• A UNION query returns all records from both A UNION query returns all records from both viewsviews

SELECT *SELECT *FROM vueSecondPersonRelationshipFROM vueSecondPersonRelationshipUNION UNION SELECT *SELECT *FROM vueFirstPersonRelationship;FROM vueFirstPersonRelationship;

– Must be entered in SQL viewMust be entered in SQL view– Normally, UNION query eliminates duplicate rowsNormally, UNION query eliminates duplicate rows

Page 21: Unary Relationships On the Job Is this a legitimate design?Is this a legitimate design? Do you see problems with it?Do you see problems with it?

A Solution for the 1:1 or M:M A Solution for the 1:1 or M:M Interpersonal Unary RelationshipInterpersonal Unary Relationship

• A UNION query returns all records from both viewsA UNION query returns all records from both views

There is only one There is only one relationship record for relationship record for persons 1 and 2, but persons 1 and 2, but both directions of the both directions of the relationship are relationship are returnedreturned


Recommended