430 likes | 556 Views
Relationships in Detail. Overview. Relationships Ten different relationship types Nontransferability Relationships that seem to have attributes Rules of Normalization. Establishing a Relationship. Determine the existence of a relationship
E N D
Overview • Relationships • Ten different relationship types • Nontransferability • Relationships that seem to have attributes • Rules of Normalization
Establishing a Relationship • Determine the existence of a relationship • Choose a name for the relationship from both perspectives • Determine optionality • Determine degree • Determine nontransferability
Establishing the Relationship USER MESSAGE sending receiving replying
Relationship Names sender of USER MESSAGE sent by sent to receiver of reply of replied to by
Naming the Relationship receiving received by USER MESSAGE receiver of A MESSAGE is received by a USER A USER is receiver of a MESSAGE
Optionality author of USER MESSAGE written by received by receiver of reply of replied to by
Optionality No: Yes: received by USER MESSAGE receiver of Yes • Must every MESSAGE be received by a USER? No • Must every USER be receiver of a MESSAGE?
B A Mandatory 1: Mandatory m split into part of • Every A must be split into at least one B • Every B must be partof exactly one A
Degree author of USER MESSAGE written by received by receiver of reply of replied to by containing <5 with ATTACHMENT
Degree One: One or more: received by USER MESSAGE receiver of • Can a MESSAGE be received by more than one USER? Yes • Can a USER be the receiver of more than one MESSAGE ? Yes
Nontransferability FOLDER containing filed in author of USER MESSAGE written by received by receiver of reply of replied to by
Relationship Types1:m (a) (b) (c) (d)
Relationship Typesm:1 PRODUCT part of BUNDLE consists of
Relationship Typesm:m (e) (f) (g)
Relationship Typesm:m USER part of LIST consists of
Relationship Types1:1 (h) ( i) ( j )
1:1 Relationships Roles acting as PATIENT* Blood Type PERSON* Name role of acting as EMPLOYEE* Job role of
1:1 Relationships Process MESSAGE DRAFT basis for result of
Redundant Relationships COUNTRY COUNTRY location of of location of of birth of located in located in TOWN TOWN hometown of hometown of living in living in born in living in PERSON PERSON
Relationships and Attributes ATTACHMENT TYPE* Name of with ATTACHMENT* Type* Content ATTACHMENT* Content • An attribute can hide a relationship • Relationship can be “downgraded” to attribute
Value control List of values Other relationships Attribute Compared to Relationship ATTACHMENT TYPE* Name of with ATTACHMENT* Type* Content ATTACHMENT* Content • Easy model • Fewer tables • No join
Attribute or Entity NAME JOB EMPLOYEE* Id SALARY BADGE GENDER NATIONALITY TEAM ADDRESS
Attribute Compared to Relationship FOLDER* Name containing placed in MESSAGE* Message Id* Text* Folder Name • There is no such thing as a foreign key attribute • Usually, the attribute name should not contain an entity name
Relationship Compared to Attribute MESSAGE addressed to USER addressee of MESSAGE* Addressee USER MESSAGEo Addressee USER addressed to addressee of
m:m Relationships May Hide Something PRODUCT * Code * Name CUSTOMER* Id * Name buyer of bought by
Quantity Is Attribute of ... ? PRODUCT CUSTOMER buyer of * Id * Name * Code * Name bought by Quantity ? PRODUCT CUSTOMER buyer of * Id * Name * Code * Name bought by Quantity
Attribute of Relationship ? PRODUCT CUSTOMER buyer of * Id * Name * Code * Name bought by Quantity
New Entity ORDER CUSTOMER* Id* Name with ORDER of PRODUCT* Code* Name *Quantity Sold with for PRODUCTS ORDERS CUSTOMERS Quantity_sold 221 Ctr_id 1123 Pdt_code 2 3 2 Code 12 3 4 Name JeansShirtTie Id 1 2 3 4 Name SanchezLowitchYomita
? Quantity Multiple PRODUCTS for an ORDER CUSTOMER* Id* Name with ORDER* Id* Date of with PRODUCT* Code* Name for
Another New Entity: ORDER ITEM CUSTOMER* Id* Name with ORDER HEADER* Id* Date of PRODUCT* Code* Name with with for for ORDER ITEM *Quantity Sold
Tables CUSTOMERS ORDER_HEADERS Id Name Date_ordered Id Ctr_id 1 2 SanchezLowitchYomita 1 2 1 2 25-MAY-1999 25-MAY-1999 25-MAY-1999 PRODUCTS ORDER_ITEMS Quantity_sold Code 12 3 4 Name JeansShirtTie Ohd_id Pdt_code 1 2 2 2 2 2 1
Resolving m:m Relationship in A A of A/B COMBINATION xxx yyy B of B in • Create new intersection entity • Create two m:1 relationships, derive optionality • Remove m:m relationship
A Resolving m:m Relationship with of A/B COMBINATION xxx yyy of B with • Create new intersection entity • Create two m:1 relationships, derive optionality • Remove m:m relationship
Resolving m:1 Relationship external classifiedas PERSON CUSTOMER TYPE classification of internal
Resolving m:1 Relationship external PERSON CUSTOMER TYPE with in for with CLASSIFICATION internal
Normalization Rules Normal Form Rule Description First Normal Form All attributes are single valued. Second Normal Form (2NF) An attribute must be dependent upon entity’s entire unique identifier. Third Normal Form (3NF) No non-UID attribute can be dependent on another non-UID attribute. “A normalized entity-relationship data model automatically translates into a normalized relational database design” “Third normal form is the generally accepted goal for a database design that eliminated redundancy”
First Normal Form in Data Modeling USER # Name * Person Name* Message Receive Dateo Message Subjecto MessageText All attributes must be single-valued. RECEIVED MESSAGE# Receive Date o Subject o Text USER # Name * Person Name received by receiver of
Second Normal Form in Data Modeling An attribute must be dependent upon its entity’s entire unique identifier. RECEIVED MESSAGE # User Name * Receive Date * Subject MESSAGE# Id o Text including included in RECEIVED MESSAGE # User Name * Receive Date MESSAGE# Id o Text including included in * Subject
No non-UID attribute can be dependent upon another non-UID attribute. Third Normal Form in Data Modeling USER# Name * Person Name * Password * Server Id * Server Name MAIL SERVER# Id * Name USER# Name * Person Name * Password assigned to distribute mail to
Summary • Relationships express how entities are connected. • Initially relationships often seem to be of type m:m. • Finally relationships are most often of type m:1. • Relationships can be resolved into: • Two new relationships • One intersection entity • Third Normal form is generally accepted standard.
Practices • Read the Relationship • Find a Context • Name the Intersection Entity • Receipt • Moonlight P&O • Price List • EMail • Holiday