47
CHAPTER 2: CHAPTER 2: MODELING DATA IN THE MODELING DATA IN THE ORGANIZATION ORGANIZATION 1 Modern Database Management

CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

Embed Size (px)

Citation preview

Page 1: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

CHAPTER 2:CHAPTER 2:MODELING DATA IN THE MODELING DATA IN THE ORGANIZATIONORGANIZATION

1

Modern Database Management

Page 2: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

OBJECTIVESOBJECTIVES

Define termsDefine terms Understand importance of data modelingUnderstand importance of data modeling Write good names and definitions for entities, Write good names and definitions for entities,

relationships, and attributesrelationships, and attributes Distinguish unary, binary, and ternary relationshipsDistinguish unary, binary, and ternary relationships Model different types of attributes, entities, Model different types of attributes, entities,

relationships, and cardinalitiesrelationships, and cardinalities Draw E-R diagrams for common business situationsDraw E-R diagrams for common business situations Convert many-to-many relationships to associative Convert many-to-many relationships to associative

entitiesentities Model time-dependent data using time stampsModel time-dependent data using time stamps

2

Page 3: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

A GOOD DATA NAME IS:A GOOD DATA NAME IS:

Related to business, not technical, Related to business, not technical, characteristicscharacteristics

Meaningful and self-documentingMeaningful and self-documenting UniqueUnique ReadableReadable Composed of words from an approved listComposed of words from an approved list RepeatableRepeatable Written in standard syntaxWritten in standard syntax

3

Page 4: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

DATA DEFINITIONSDATA DEFINITIONS

Explanation of a term or factExplanation of a term or fact Term–word or phrase with specific meaningTerm–word or phrase with specific meaning Fact–association between two or more termsFact–association between two or more terms

Guidelines for good data definitionGuidelines for good data definition A concise description of essential data meaningA concise description of essential data meaning Gathered in conjunction with systems Gathered in conjunction with systems

requirementsrequirements Accompanied by diagramsAccompanied by diagrams Achieved by consensus, and iteratively refinedAchieved by consensus, and iteratively refined

4

Page 5: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

E-R MODEL E-R MODEL CONSTRUCTSCONSTRUCTS

Entities:Entities: Entity instance–person, place, object, event, concept Entity instance–person, place, object, event, concept

(often corresponds to a row in a table)(often corresponds to a row in a table) Entity Type–collection of entities (often corresponds to a Entity Type–collection of entities (often corresponds to a

table)table) Relationships:Relationships:

Relationship instance–link between entities (corresponds Relationship instance–link between entities (corresponds to primary key-foreign key equivalencies in related tables)to primary key-foreign key equivalencies in related tables)

Relationship type–category of relationship…link between Relationship type–category of relationship…link between entity typesentity types

Attributes:Attributes: Properties or characteristics of an entity or relationship Properties or characteristics of an entity or relationship

type (often corresponds to a field in a table)type (often corresponds to a field in a table)

5

Page 6: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

6

Sample E-R Diagram (Figure 2-1)

6

Page 7: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

7

Relationship degrees specify number of entity types involved

Entity symbols

A special entity that is also a relationship

Relationship symbols

Relationship cardinalities specify how many of each entity type is allowed

Attribute symbols

Basic E-R notation (Figure 2-2)

7

Page 8: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

BUSINESS RULESBUSINESS RULES

Are statements that define or constrain Are statements that define or constrain some aspect of the businesssome aspect of the business

Are derived from policies, procedures, Are derived from policies, procedures, events, functionsevents, functions

Assert business structureAssert business structure Control/influence business behaviorControl/influence business behavior Are expressed in terms familiar to end usersAre expressed in terms familiar to end users Are automated through DBMS softwareAre automated through DBMS software

8

Page 9: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

A GOOD BUSINESS RULE IS:A GOOD BUSINESS RULE IS:

Declarative–what, not howDeclarative–what, not how Precise–clear, agreed-upon meaningPrecise–clear, agreed-upon meaning Atomic–one statementAtomic–one statement Consistent–internally and externallyConsistent–internally and externally Expressible–structured, natural Expressible–structured, natural

languagelanguage Distinct–non-redundantDistinct–non-redundant Business-oriented–understood by Business-oriented–understood by

business peoplebusiness people

9

Page 10: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

ENTITIESENTITIES

EntityEntity – a person, a place, an – a person, a place, an object, an event, or a concept in object, an event, or a concept in the user environment about which the user environment about which the organization wishes to the organization wishes to maintain datamaintain data

Entity typeEntity type – a collection of – a collection of entities that share common entities that share common properties or characteristicsproperties or characteristics

Entity instanceEntity instance – A single – A single occurrence of an entity typeoccurrence of an entity type

10

Page 11: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

ENTITY TYPE AND ENTITY ENTITY TYPE AND ENTITY INSTANCESINSTANCES

11

Page 12: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

AN ENTITY…AN ENTITY…

SHOULD BE:SHOULD BE: An object that will have many An object that will have many

instances in the databaseinstances in the database An object that will be composed of An object that will be composed of

multiple attributesmultiple attributes An object that we are trying to modelAn object that we are trying to model

SHOULD NOT BE:SHOULD NOT BE: A user of the database system A user of the database system An output of the database system An output of the database system

(e.g., a report)(e.g., a report)

12

Page 13: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

13

Inappropriate entities

System System useruser

System System outputoutput

Figure 2-4 Example of inappropriate entities

Appropriate entities

Page 14: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

STRONG VS. WEAK ENTITIES, STRONG VS. WEAK ENTITIES, ANDANDIDENTIFYING RELATIONSHIPSIDENTIFYING RELATIONSHIPS Strong entity Strong entity

exists independently of other types of entitiesexists independently of other types of entities has its own unique identifierhas its own unique identifier

identifier underlined with single lineidentifier underlined with single line

Weak entityWeak entity dependent on a strong entity (identifying owner)…cannot exist dependent on a strong entity (identifying owner)…cannot exist

on its ownon its own does not have a unique identifier (only a partial identifier)does not have a unique identifier (only a partial identifier) entity box and partial identifier have double linesentity box and partial identifier have double lines

Identifying relationshipIdentifying relationship links strong entities to weak entitieslinks strong entities to weak entities

14

Page 15: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

15

Strong entity Weak entity

Figure 2-5 Example of a weak identity and its identifying relationship

Page 16: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

ATTRIBUTESATTRIBUTES

Attribute–property or characteristic of Attribute–property or characteristic of an entity or relationship typean entity or relationship type

Classifications of attributes:Classifications of attributes: Required versus Optional AttributesRequired versus Optional Attributes Simple versus Composite AttributeSimple versus Composite Attribute Single-Valued versus Multivalued Single-Valued versus Multivalued

AttributeAttribute Stored versus Derived AttributesStored versus Derived Attributes Identifier AttributesIdentifier Attributes

16

Page 17: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

REQUIRED VS. OPTIONAL REQUIRED VS. OPTIONAL ATTRIBUTESATTRIBUTES

17

Required – must have a value for every entity (or relationship) instance with which it is associated

Optional – may not have a value for every entity (or relationship) instance with which it is associated

Page 18: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

SIMPLE VS. COMPOSITE SIMPLE VS. COMPOSITE ATTRIBUTESATTRIBUTES

Composite attributeComposite attribute – An attribute that has – An attribute that has meaningful component parts (attributes)meaningful component parts (attributes)

18

The address is broken into component parts

Figure 2-7 A composite attribute

Page 19: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

19

Figure 2-8 Entity with multivalued attribute (Skill) and derived attribute (Years Employed)

Multivaluedan employee can have more than one skill

DerivedCalculated from date employed and current date

Multi-valued and Derived Multi-valued and Derived AttributesAttributes

Multivalued – may take on more than one value for a given entity (or relationship) instance

Derived – values can be calculated from related attribute values (not physically stored in the database)

19

Page 20: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

IDENTIFIERS (KEYS)IDENTIFIERS (KEYS)

Identifier (Key)–an attribute (or Identifier (Key)–an attribute (or combination of attributes) that combination of attributes) that uniquely identifies individual uniquely identifies individual instances of an entity typeinstances of an entity type

Simple versus Composite IdentifierSimple versus Composite Identifier Candidate Identifier–an attribute Candidate Identifier–an attribute

that could be a key…satisfies the that could be a key…satisfies the requirements for being an identifierrequirements for being an identifier

20

Page 21: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

CRITERIA FOR IDENTIFIERSCRITERIA FOR IDENTIFIERS

Choose Identifiers thatChoose Identifiers that Will not change in valueWill not change in value Will not be nullWill not be null

Avoid intelligent identifiers (e.g., Avoid intelligent identifiers (e.g., containing locations or people that might containing locations or people that might change)change)

Substitute new, simple keys for long, Substitute new, simple keys for long, composite keyscomposite keys

21

Page 22: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

22

Figure 2-9 Simple and composite identifier attributes

The identifier is boldfaced and underlined

22

Page 23: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

NAMING ATTRIBUTESNAMING ATTRIBUTES

Name should be a singular noun or noun Name should be a singular noun or noun phrasephrase

Name should be uniqueName should be unique Name should follow a standard formatName should follow a standard format

e.g. e.g. [Entity type name { [ Qualifier ] } ] Class[Entity type name { [ Qualifier ] } ] Class

Similar attributes of different entity types Similar attributes of different entity types should use the same qualifiers and classesshould use the same qualifiers and classes

23

Page 24: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

DEFINING ATTRIBUTESDEFINING ATTRIBUTES

State what the attribute is and possibly why it is State what the attribute is and possibly why it is importantimportant

Make it clear what is and is not included in the Make it clear what is and is not included in the attribute’s valueattribute’s value

Include aliases in documentationInclude aliases in documentation State source of valuesState source of values Specify required vs. optionalSpecify required vs. optional State min and max number of occurrences allowedState min and max number of occurrences allowed Indicate relationships with other attributesIndicate relationships with other attributes

24

Page 25: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

MODELING RELATIONSHIPSMODELING RELATIONSHIPS

Relationship Types vs. Relationship InstancesRelationship Types vs. Relationship Instances The relationship type is modeled as lines between The relationship type is modeled as lines between

entity types…the instance is between specific entity types…the instance is between specific entity instancesentity instances

Relationships can have attributesRelationships can have attributes These describe features pertaining to the association These describe features pertaining to the association

between the entities in the relationshipbetween the entities in the relationship

Two entities can have more than one type of Two entities can have more than one type of relationship between them (multiple relationship between them (multiple relationships)relationships)

Associative Entity–combination of Associative Entity–combination of relationship and entityrelationship and entity

25

Page 26: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

26

Figure 2-10 Relationship types and instances

a) Relationship type (Completes)

b) Relationship instances

26

Page 27: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

DEGREE OF RELATIONSHIPSDEGREE OF RELATIONSHIPS

Degree of a relationship is Degree of a relationship is the number of entity types the number of entity types that participate in itthat participate in it Unary RelationshipUnary Relationship Binary RelationshipBinary Relationship Ternary RelationshipTernary Relationship

27

Page 28: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

28

Degree of relationships – from Figure 2-2

Entities of two different types related to each other

Entities of three different types related to each other

One entity related to another of the same entity type

28

Page 29: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

CARDINALITY OF RELATIONSHIPSCARDINALITY OF RELATIONSHIPS

One-to-OneOne-to-One Each entity in the relationship will have exactly Each entity in the relationship will have exactly

one related entityone related entity One-to-ManyOne-to-Many

An entity on one side of the relationship can An entity on one side of the relationship can have many related entities, but an entity on have many related entities, but an entity on the other side will have a maximum of one the other side will have a maximum of one related entityrelated entity

Many-to-ManyMany-to-Many Entities on both sides of the relationship can Entities on both sides of the relationship can

have many related entities on the other sidehave many related entities on the other side

29

Page 30: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

30

Figure 2-12 Examples of relationships of different degrees

a) Unary relationships

30

Page 31: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

31

Figure 2-12 Examples of relationships of different degrees (cont.)

b) Binary relationships

31

Page 32: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

32

Figure 2-12 Examples of relationships of different degrees (cont.)

c) Ternary relationship

Note: a relationship can have attributes of its own

32

Page 33: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

CARDINALITY CONSTRAINTSCARDINALITY CONSTRAINTS Cardinality Constraints—the number of Cardinality Constraints—the number of

instances of one entity that can or must instances of one entity that can or must be associated with each instance of be associated with each instance of another entityanother entity

Minimum CardinalityMinimum Cardinality If zero, then optionalIf zero, then optional If one or more, then mandatoryIf one or more, then mandatory

Maximum CardinalityMaximum Cardinality The maximum numberThe maximum number

33

Page 34: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

34

Figure 2-17 Examples of cardinality constraints

a) Mandatory cardinalities

A patient must have recorded at least one history, and can have many

A patient history is recorded for one and only one patient

34

Page 35: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

35

Figure 2-17 Examples of cardinality constraints (cont.)

b) One optional, one mandatory

An employee can be assigned to any number of projects, or may not be assigned to any at all

A project must be assigned to at least one employee, and may be assigned to many

35

Page 36: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

36

Figure 2-17 Examples of cardinality constraints (cont.)

c) Optional cardinalities

A person is married to at most one other person, or may not be married at all

36

Page 37: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

37

Entities can be related to one another in more than one way

Figure 2-21 Examples of multiple relationships

a) Employees and departments

37

Page 38: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

38

Figure 2-21 Examples of multiple relationships (cont.)

b) Professors and courses (fixed lower limit constraint)

Here, min cardinality constraint is 2. At least two professors must be qualified to teach each course. Each professor must be qualified to teach at least one course.

38

Page 39: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

39

Figure 2-15a and 2-15b Multivalued attributes can be represented as relationships

simple

composite

39

Page 40: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

ASSOCIATIVE ENTITIESASSOCIATIVE ENTITIES An entity–has attributesAn entity–has attributes A relationship–links entities togetherA relationship–links entities together When should a When should a relationship with attributesrelationship with attributes instead be an instead be an

associative entityassociative entity? ? All relationships for the associative entity should be manyAll relationships for the associative entity should be many The associative entity could have meaning independent of the The associative entity could have meaning independent of the

other entitiesother entities The associative entity preferably has a unique identifier, and The associative entity preferably has a unique identifier, and

should also have other attributesshould also have other attributes The associative entity may participate in other relationships The associative entity may participate in other relationships

other than the entities of the associated relationshipother than the entities of the associated relationship Ternary relationships should be converted to associative entitiesTernary relationships should be converted to associative entities

40

Page 41: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

41

Figure 2-11a A binary relationship with an attribute

Here, the date completed attribute pertains specifically to the employee’s completion of a course…it is an attribute of the relationship.

41

Page 42: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

42

Figure 2-11b An associative entity (CERTIFICATE)

Associative entity is like a relationship with an attribute, but it is also considered to be an entity in its own right.

Note that the many-to-many cardinality between entities in Figure 2-11a has been replaced by two one-to-many relationships with the associative entity.

42

Page 43: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

43

Figure 2-13c An associative entity – bill of materials structure

This could just be a relationship with attributes…it’s a judgment call.

43

Page 44: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

44

Figure 2-18 Cardinality constraints in a ternary relationship

44

Page 45: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

45

Figure 2-19 Simple example of time-stamping

The Price History attribute is both multivalued and composite.

Time stamp – a time value that is associated with a data value, often indicating when some event occurred that affected the data value

45

Page 46: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

46

Figure 2-20c E-R diagram with associative entity for product assignment to product line over time

The Assignment associative entity shows the date range of a product’s assignment to a particular product line.

Modeling time-dependent data has become more important due to regulations such as HIPAA and Sarbanes-Oxley.

46

Page 47: CHAPTER 2: MODELING DATA IN THE ORGANIZATION 1 Modern Database Management

47

Figure 2-22Data model for Pine Valley Furniture Company in Microsoft Visio notation

Different modeling software tools may have different notation for the same constructs.

47