Presentation is loading. Please wait.

Presentation is loading. Please wait.

IMS 4212: Data Modeling—More Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida Data Modeling—Topics.

Similar presentations


Presentation on theme: "IMS 4212: Data Modeling—More Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida Data Modeling—Topics."— Presentation transcript:

1 IMS 4212: Data Modeling—More Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Data Modeling—Topics Foreign Keys Parent-Child Relationships Strong-Weak Entities Many to Many relationships Unary Relationships n-ary relationships Binary 1:1 relationships

2 IMS 4212: Data Modeling—More Relationships 2 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Foreign Keys Relationships are established when the Primary Key attribute(s) of one entity is/are found in another entity These attributes are called Foreign Keys in the other entity Foreign Keys

3 IMS 4212: Data Modeling—More Relationships 3 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Parent & Child Relationships (Terminology) The entity contributing the primary key is the parent The entity receiving the foreign key is the child Foreign Keys always, always, always go on the ‘many’ side of a 1:M relationship Identifier Attribute Shared Identifier Attribute (Foreign Key) ParentChild

4 IMS 4212: Data Modeling—More Relationships 4 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Strong & Weak Entity Types Traditional definitions: –Strong entity type exists independently of any other entity –Weak entity type depends on some other entity type Strong Entity Type Weak Entity Type

5 IMS 4212: Data Modeling—More Relationships 5 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Strong & Weak Entity Types (cont.) Identifying weak entities will often not happen until identifier attributes are specified When the Identifier Attribute of one entity appears as an attribute in another entity a relationship is established If the foreign key in the child table is not part of the child's PK the child is a strong entity Identifier Attribute Shared Identifier Attribute

6 IMS 4212: Data Modeling—More Relationships 6 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Strong & Weak Entity Types (cont.) When the identifying attribute of one entity appears as part of a composite identifying attribute set in another entity the child entity is a weak entity Dept Code part of Course PK Indicates Weak Entity in some documentation styles (We will not use.) Parent (Strong) Child (Weak)

7 IMS 4212: Data Modeling—More Relationships 7 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Strong vs. Weak Entity Types (Terminology) The identifying attribute that appears in the composite identifying attribute in a weak entity is sometimes called a cascading primary key. These primary key attributes can sometimes cascade through three or more entities Do not confuse mandatory relationships with weak entities

8 IMS 4212: Data Modeling—More Relationships 8 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Many-to-Many Relationships What is the problem with implementing foreign keys for the following Many-to-Many relationships?

9 IMS 4212: Data Modeling—More Relationships 9 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Many-to-Many Relationships (cont.) Many-to-Many (M:N) relationships must be decomposed into a new entity and two relationships Carefully examine the cardinality of the two new relationships If one is still M:N then decompose again

10 IMS 4212: Data Modeling—More Relationships 10 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Many-to-Many Relationships (cont.) Always try the combination of the primary keys from the two original entities as the PK of the new entity –Sometimes not all attributes of a composite parent PK are needed –Sometimes an alternate PK suggests itself –Sometimes this proposed PK is not unique Add appropriate nonkey attributes to the new entity –Sometimes there won't be any—the new entity serves no role but to decompose the M:N relationship

11 IMS 4212: Data Modeling—More Relationships 11 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Decomposing Many to Many Relationships Create a new entity Bring in PKs of original entities to the new entity Ask if the combination of these FKs can be the PK of the new entity –Defines the entity –Is enough to guarantee uniqueness –Is more than enough to guarantee uniqueness What is the new entity? Does a different PK suggest itself

12 IMS 4212: Data Modeling—More Relationships 12 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Decomposing Many to Many Relationships (cont.) Determine the cardinality of the relationships from the original entities to the new entity If one (or both) are still many-to-many decompose again

13 IMS 4212: Data Modeling—More Relationships 13 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Many-to-Many Relationships (cont.) Two kinds of entities created this way –A real ‘person, place, thing, event…’ that was overlooked in the original design –An ‘associative entity’ that has no purpose except to decompose the M:M relationship The distinction isn’t terribly important Both kinds can have non-key attributes

14 IMS 4212: Data Modeling—More Relationships 14 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Many-to-Many Relationships (cont.) Decompose this relationship Sometimes the new entity has a natural meaning that should have been identified in the original data modeling step

15 IMS 4212: Data Modeling—More Relationships 15 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Unary Relationships Unary relationships are relationships between an entity and itself –One employee supervises many other employees; each employee is supervised by, at most, one other employee –One part is a component of many other parts; One part (assembly) contains many other parts

16 IMS 4212: Data Modeling—More Relationships 16 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu EmployeeIDLastNameFirstName…ReportsTo 3JonesSally…9 5JeffersonMark…3 6WilsonJohn…3 8AdamskiJustin…9 9BossBig…9 13DowdRuss…6 19BrownLarry…9 Unary Relationships and Foreign Keys The foreign key in a unary relationship will be a different attribute in the entity

17 IMS 4212: Data Modeling—More Relationships 17 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Decomposing Unary M:N relationships Unary Many-to-Many Relationships

18 IMS 4212: Data Modeling—More Relationships 18 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Unary M:M Relationships (cont.) Fix this one

19 IMS 4212: Data Modeling—More Relationships 19 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Ternary Relationships Ternary (or n-ary) relationships are relationships between three (or more) entities It will almost always be possible to identify a natural associative entity that reflects the relationship between the entities Create the weak associative entity and bring in foreign keys from the original entities

20 IMS 4212: Data Modeling—More Relationships 20 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Ternary Relationships (cont.) In n-ary relationships there is a higher likelihood that the new entity will have its own 'natural' PK Examine the default PK carefully to see if it is appropriate Can you think of an alternate PK for the HouseSale entity? (What other entities are likely to be related to the HouseSale entity?)

21 IMS 4212: Data Modeling—More Relationships 21 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Binary 1:1 Relationships In a 1:M relationship the parent entity will always be on the '1' side of the relaionship –Foreign key will be in the 'M' side Q: Where should the FK be in a 1:1 relationship?

22 IMS 4212: Data Modeling—More Relationships 22 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Binary 1:1 Relationships (cont.) A: It doesn't matter (much) Some considerations –Use the simplest PK/FK available –If there is a 'natural' parent (e.g., employee 'owns' the office, not the other way around) make it the parent –If an occurrence of one member of the relationship may stand alone (not participate in a relationship) while the other will usually be in a relationship make it the parent


Download ppt "IMS 4212: Data Modeling—More Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida Data Modeling—Topics."

Similar presentations


Ads by Google