ims 4212: introduction to data modeling—relationships 1 dr. lawrence west, management dept.,...

28
IMS 4212: Introduction to Data Modeling— Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida [email protected] Relationships—Topics Goal of the Relational Data Model Introducing Relationships Relationship Notation Schemes Binary Relationships Relationship Cardinality & Notation Policy and Cardinality Recursive (Unary) Relationships Ternary Relationships Relationships with Attributes The Road Ahead

Upload: asher-george

Post on 04-Jan-2016

223 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

1Dr. Lawrence West, Management Dept., University of Central [email protected]

Relationships—Topics

• Goal of the Relational Data Model

• Introducing Relationships

• Relationship Notation Schemes

• Binary Relationships

• Relationship Cardinality & Notation

• Policy and Cardinality

• Recursive (Unary) Relationships

• Ternary Relationships

• Relationships with Attributes

• The Road Ahead

Page 2: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

2Dr. Lawrence West, Management Dept., University of Central [email protected]

The Goal of the Relational Data Model

• Recall that entities hold data about one type of object or event of interest to the organization

• A goal of the relational data model is to minimize the amount of stored data subject to:

– Necessity to record data needed by the organization

– Necessity to maintain relationships

Page 3: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

3Dr. Lawrence West, Management Dept., University of Central [email protected]

The Goal of the Relational Data Model (cont).

• Data minimization is achieved by removing any redundant data

– Achieved through good entity and relationship design

– Normalization

• Our approach

– Design properly normalized (minimal redundancy) data structures

– Selectively denormalize (introduce redundancy) to improve performance

Page 4: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

4Dr. Lawrence West, Management Dept., University of Central [email protected]

The Goal of the Relational Data Model (cont).

• DB design results in many tables, sometimes for simple organizational needs

– Identifying entities from information requirements analysis

– Creating new entities to fix attribute-level and relationship problems (covered soon)

• Relationships between tables enable us to reconnect data that is dispersed into many tables

Page 5: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

5Dr. Lawrence West, Management Dept., University of Central [email protected]

Relationships

• "A meaningful association between (or among) entities"

• What in the world does this mean?

• Relationships indicate how entities interact from the organization's perspective

• Relationships will end up defining paths through the database along which data will be retrieved

– The paths usually mirror real world associations between entities

Page 6: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

6Dr. Lawrence West, Management Dept., University of Central [email protected]

Relationships (cont.)

• While entities are nouns relationships are verbs

– Buys, teaches, sells, owns, …

– Is a

– Has

• Relationship verb describes how two entities interact with each other

• If two entities do not interact (from the organization’s official viewpoint) then there is no relationship between them

– Professor ?? Football_Play

• ‘Direction’ of verb is not very important

Important special cases

Page 7: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

7Dr. Lawrence West, Management Dept., University of Central [email protected]

Introducing Relationships

• Relationships are defined in three ways

– In data modeling by conceptually identifying and documenting the fact that two entities do relate to each other

– In data modeling by identifying shared attributes between the two entities

– In the physical database by implementing common attributes and declaring the relationship

Page 8: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

8Dr. Lawrence West, Management Dept., University of Central [email protected]

Introducing Relationships (cont.)

• Relationships are the glue that connects different stored data in a way that meets the organization’s needs

• File-based vs. Relational systems

– In file-based systems each transaction record had all necessary data stored with it, including redundant copies of data

– In relational systems only data of a particular type is stored in each entity (table)—little redundancy

• Relationships allow the system to reconstruct the logic of a transaction

Page 9: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

9Dr. Lawrence West, Management Dept., University of Central [email protected]

Introducing Relationships (cont.)

• We deal with relationships in three ways

– Modeling relationships as part of a process of discovery of the organization’s structure, etc

– Adapting or correcting the relationships we find into the form required for database implementation

– Implementing the relationships in the physical database

STUDENT CLASSTakes

Page 10: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

10Dr. Lawrence West, Management Dept., University of Central [email protected]

Two Notation Schemes (Chen LDM)

STUDENT Takes CLASS

SSNLast

NameFirst

NameName

Entities are indicated by a box with the entity nameinside

Attributes are listed in ovalsattached to entities

Relationships are indicatedby diamonds

Relationships are connectedto entities by notation toindicate the cardinality ofthe relationship

Page 11: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

11Dr. Lawrence West, Management Dept., University of Central [email protected]

Two Notation Schemes (Alternative LDM)

SSNLastNameFirstName

STUDENT

DepartmentNumberName

CLASSTakes

Entities shown as boxes

Entity name

Attributes

Relationship shown withoutthe diamond

Page 12: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

12Dr. Lawrence West, Management Dept., University of Central [email protected]

Binary Relationships

• The most commonly found relationship is between two entities (binary)

STUDENT Takes CLASS

SSNLastNameFirstName

STUDENT

DepartmentNumberName

CLASSTakes

Entities EntitiesRelationship

Cardinality Cardinality

Chen Diagram

My Approach

Page 13: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

13Dr. Lawrence West, Management Dept., University of Central [email protected]

Cardinality

• Understanding “Cardinality” is one of the most fundamentally important concepts in DB design

• Cardinality indicates how many occurrences of an entity must or may be allowed in the relationship with any one occurrence in the other entity

• Cardinality goes in each direction

– One student may/must take ? Classes

– One class must/may be taken by ? Students

SSNLastNameFirstName

STUDENT

DepartmentNumberName

CLASSTakes

Page 14: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

14Dr. Lawrence West, Management Dept., University of Central [email protected]

Relationship Cardinality (cont.)

• The measure of cardinality has two components at each end of the relationship:

– A maximum (usually either 1 or an unconstrained number greater than one, referred to as “many”)

– A minimum (usually either 0 or 1 but other values are possible, though rare)

• Relationship is mandatory if at least one matching record is required (minimum is 1)

• Relationship is optional if a matching record is not required (minimum is 0)

Page 15: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

15Dr. Lawrence West, Management Dept., University of Central [email protected]

SSNLastNameFirstName

STUDENT

DepartmentNumberName

CLASSTakes

Cardinality Notation

• Mandatory One

– One professor must have exactly one phone number

• Mandatory Many

– A customer must have at least one purchase to be a customer but may have many

• Optional One

– One professor may have as few as zero reserved parking spaces but may have only one at most

• Optional Many

– One student may take as few as zero classes but may take more than one class

Page 16: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

16Dr. Lawrence West, Management Dept., University of Central [email protected]

Cardinality Notation (cont.)

• Interpret these cardinalities

SalesRep SaleMakes

Sale CustomerHas

TrafficCitation DriverHas

Employee OfficeHas

Page 17: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

17Dr. Lawrence West, Management Dept., University of Central [email protected]

Cardinality Notation (cont.)

• Relationship cardinality is governed by the number of related occurrences you could have

– If a student could have two majors then relationship is ‘Many’ on the Major side

– May a car or house have more than one owner?

– May an Employee be assigned to more than one job title at a time?

– Will you record a Supplier if you do not currently carry any of their products?

– Will you enter an Employee without assigning them to a position?

Page 18: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

18Dr. Lawrence West, Management Dept., University of Central [email protected]

Cardinality Notation (cont.)

• Commonly used verbal shorthand ignores the minimum component of a relationship

• 1:M (one-to-many)

• 1:1 (one-to-one)

• M:M (or M:N) (many-to-many)

Employee OfficeHas

Sale CustomerHas

Student MajorHas

Page 19: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

19Dr. Lawrence West, Management Dept., University of Central [email protected]

Cardinality Notation (cont.)

• The graphical layout of a relationship is purely arbitrary

SaleCustomer Has

Sale CustomerHas

Sale

Customer

Has

Page 20: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

20Dr. Lawrence West, Management Dept., University of Central [email protected]

Organization Policy and Cardinality

• Business policies (or regulations) may affect cardinality

• Identify legitimate business policies that support each of the different cardinality combinations reflected here

Sale CustomerHas

Sale CustomerHas

Sale CustomerHas

Page 21: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

21Dr. Lawrence West, Management Dept., University of Central [email protected]

StoreEmployeeSaleProductEmployeeShiftDepartment

Page 22: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

22Dr. Lawrence West, Management Dept., University of Central [email protected]

Unary Relationships

• Unary relationships are relationships between an entity and itself

– One employee supervises many other employees; eachemployee is supervisedby, at most, one otheremployee

– One part is a component ofmany other parts;One part (assembly)contains manyother parts

Employee Supervises

Part Is ComposedOf

Page 23: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

23Dr. Lawrence West, Management Dept., University of Central [email protected]

Ternary Relationships

• A ternary relationship is one between three entities

• This relationship isfor modeling and discoveryonly

– Model the relationship the way the user describes it

– Recognize that there are problems with implementing this relationship

• Relationship will be decomposed into multiple binary relationships for the final ERD

– (What is the solution?)

Sells P roductSa lesR ep

C ustom er

Page 24: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

24Dr. Lawrence West, Management Dept., University of Central [email protected]

Attributes on Relationships

• The modeling processwill sometimes produceattributes of relationships

• These also will be eliminatedin the final ERD

– (What is the solution?)

• Look for the missing entityand implement it now

S ells P roductS a lesR ep

D ate Q ty

Page 25: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

25Dr. Lawrence West, Management Dept., University of Central [email protected]

Multiple Relationships

• Sometimes there can be two relationships between the same two entities

Sells

ProductCompany

Services

Page 26: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

26Dr. Lawrence West, Management Dept., University of Central [email protected]

Implementing Relationships

• Relationships are implemented by sharing attributes between entities

• When the Identifier Attribute of one entity appears as an attribute in another entity set a relationship is established (whether you intended it or not)

• These shared identifier attributes are called foreign keys (more next time)

SSNLNameFName

Student

NumberSSNTagNo

TicketGets

IdentifierAttribute

SharedIdentifierAttribute

Page 27: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

27Dr. Lawrence West, Management Dept., University of Central [email protected]

Problem Relationships

• Ternary relationships, attributes on relationships, multiple relationships, and Many-to-Many relationships all have serious implementation problems

• What are they?

• What does the nature of the problem tell us about what we should do to fix it?

Page 28: IMS 4212: Introduction to Data Modeling—Relationships 1 Dr. Lawrence West, Management Dept., University of Central Florida lwest@bus.ucf.edu Relationships—Topics

IMS 4212: Introduction to Data Modeling—Relationships

28Dr. Lawrence West, Management Dept., University of Central [email protected]

Next Time

• Parent and Child Relationships

• Strong & Weak Entities

• Time- and Space-Dependent Data

• Supertype/Subtype entity sets