44
Chapter 8 Conceptual Data Modeling ( 概概概概概概概概 )

Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline Three main phases of database design Use ER modeling technique to build an

Embed Size (px)

Citation preview

Page 1: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

Chapter 8

Conceptual Data Modeling

(概念性的資料建模 )

Page 2: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-2

Chapter OutlineChapter Outline

Three main phases of database design

Use ER modeling technique to build an ER model

Document the process of conceptual data modeling

The produced documents

Entity–Relationship (ER) diagrams

A data dictionary

Page 3: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-3

Phases Of Database DesignPhases Of Database Design

Database design has 3 main phases: Conceptual data modeling

Building conceptual representation of the database Identifying important entities, relationships, and attributes

Logical database design Translate conceptual representation into logical structure of a

databaseConvert the conceptual model into a set of tables

Physical database design Tailor tables to a specific DBMS (針對一個特定的 DBMS)

Decide how the logical structure of the database is to be physically implemented in the target DBMS

Page 4: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-4

Conceptual Data ModelingConceptual Data Modeling

The output of this step is an ER model.

The model is a representation for the data requirements

of an organization that is to be supported by a

database.

Need to check that

the model is capable of supporting user transactions.

Page 5: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-5

Steps In Conceptual Data ModelingSteps In Conceptual Data Modeling

Step 1 Create and check ER modelStep 1.1 Identify entitiesStep 1.2 Identify relationshipsStep 1.3 Identify attributes associated with entities

or relationshipsStep 1.4 Determine attribute domainsStep 1.5 Determine candidate, primary, and alternate

key attributesStep 1.6 Check that model supports user transactionsStep 1.7 Review model with user

Page 6: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-6

Conceptual Data ModelingConceptual Data Modeling

In requirements collection and analysis stage (Chapter 4.4.4: Fact-finding), two merged views were identified for StayHome :

Branch View: consisting Manager, Supervisor, and Assistant user views

Business View: consisting Director and Buyer user views

In this chapter, we will build a local conceptual data model for the Branch View

Page 7: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-7

Managing The User ViewsManaging The User Views

Branch view

Merge the requirements for the Manager, Supervisor, and Assistant user views

Page 8: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-8

Step 1Step 1Create And Check ER ModelCreate And Check ER Model

ObjectiveTo build an ER model for the data requirements of an

organization (or part of an organization) to be supported by the database

ER data model comprises: Entities Relationships Attributes and Attribute Domains Primary Keys, and Alternate Keys Integrity Constraints

Step 1 Create and Check ER Model

Page 9: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-9

Step 1.1 Step 1.1 Identify EntitiesIdentify Entities

Objective

To identify the main entities required by users.

“What type of data do the users work with?”

Look for

objects that have an existence in their own righte.g., objects such as people, places, or concepts of

interest : nouns or noun phrases

Step 1 Create and Check ER Model

Page 10: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-10

Identify EntitiesIdentify Entities

For example:

Staff is an entity because staff exist whether or not you

know their names, addresses, and salaries.

Grouping staff ID number and staff name into an

entity called Staff

Videos have an independent existence

Grouping video catalog number, title, daily rental

rate, and purchase price into an entity called Video

Step 1.1 Identify entities

Page 11: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-11

Examples of identified EntitiesExamples of identified Entities

For the Branch user views of StayHome, you may

identify the following entities

BranchVideoMemberActor

BranchVideoMemberActor

StaffVideoForRentRentalAgreementDirector

StaffVideoForRentRentalAgreementDirector

Step 1.1 Identify entities

Page 12: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-12

Document Entities In Data DictionaryDocument Entities In Data Dictionary

Step 1.1 Identify entities

Page 13: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-13

Step 1.2 Step 1.2 Identify RelationshipsIdentify Relationships

Objective

To identify the important relationships that exist

between the identified entities

Indicated by verbs or verbal expressions

Branch Has Staff

Branch IsAllocated VideoForRent

VideoForRent IsPartOf RentalAgreement

Step 1.2 Identify relationships

Page 14: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-14

Identify RelationshipsIdentify Relationships

Focus on required relationships between entities.

Ensure that all explicit or implicit relationships in the

users' requirements specification are noted.

Usually, missing relationships become apparent when

you check that the model supports the transactions

required by users.

It is possible, but very rare, that an entity can have no

relationship with other entities in the database but still

play an important part in meeting the users'

requirements.

Step 1.2 Identify relationships

Page 15: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-15

Identify RelationshipsIdentify Relationships

In most cases, the relationships will be binary. Be careful to look out for

complex relationships involving more than two entities recursive relationships involving only one entity

For the Branch user views of StayHome, the following non-binary relationships are identified : Registers: a ternary relationship involving Branch,

Member, and Staff Supervises: a recursive relationship involving Staff.

Step 1.2 Identify relationships

Page 16: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-16

First Draft Of The RelationshipsFirst Draft Of The Relationships

Step 1.2 Identify relationships

ERDERD

Page 17: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-17

First Draft Of The ER Diagram First Draft Of The ER Diagram

Step 1.2 Identify relationships

Page 18: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-18

Determine Multiplicity (Determine Multiplicity ( 多重性多重性 ) Constraints ) Constraints of Relationshipsof Relationships

Step 1.2 Identify relationships

ERD

Page 19: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-19

Adding Multiplicity Constraints to the ER Adding Multiplicity Constraints to the ER ModelModel

Step 1.2 Identify relationships

Page 20: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-20

Identify RelationshipsIdentify Relationships

Document relationships in Document relationships in datadata dictionarydictionary

Step 1.2 Identify relationships

Page 21: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-21

Step 1.3 Identify the Attributes Associated with Step 1.3 Identify the Attributes Associated with Entities or RelationshipsEntities or Relationships

Objective

To associate attributes with the appropriate entities

or relationships

Step 1.3 Identify the attributes associated with entities or relationships

1. What1. What typetype ofof datadata dodo youyou workwork withwith??

2. What2. What typetype ofof datadata dodo youyou needneed toto holdhold onon youryour X? X?

Typical questions given to users :

Page 22: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-22

Simple/Composite AttributesSimple/Composite Attributes

The option to represent address as a simple or composite attribute is determined by the users' requirements.

Example: lf users do not need to access the separate

components of an address, you should represent the address as a simple attribute.

If users do need to access the individual components of an address, you should represent the address as a composite attribute, made up of the required simple attributes.

Step 1.3 Identify the attributes associated with entities or relationships

Page 23: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-23

Single/Multi-valued AttributesSingle/Multi-valued Attributes

Most attributes will be single-valued, but occasionally you may encounter a multi-valued attribute

For example, you may identify the Branch attribute telNo (telephone number) as a multi-valued attribute, ora separate entity.

This is an alternative, and equally valid, way to model that a branch has several telephones.

In Step 2.1, multi-valued attributes are mapped to tables, so both approaches produce the same result.

Step 1.3 Identify the attributes associated with entities or relationships

Page 24: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-24

Derived Attributes Derived Attributes ((衍生的屬性衍生的屬性 ))

Attributes whose values can be found by examining the

values of other attributes.

All derived attributes must be shown in the data model

to avoid a potential loss of information, which may

occur if the attribute or attributes on which the derived

attribute is based are deleted or modified.

Step 1.3 Identify the attributes associated with entities or relationships

Page 25: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-25

Potential ProblemsPotential Problems((Attributes associated with more than one entity))

Attributes seem to be associated with more than one

Entity. This can indicate the following:

1. It may be that you’ve identified several entities that can

be represented as a single entity.

For example, you may have identified entities

Manager and Supervisor both with the attributes

staffNo (staff number), name, and salary, which can

be represented as a single entity called Staff with the

attributes staffNo, name, position, and salary.

Step 1.3 Identify the attributes associated with entities or relationships

Page 26: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-26

2. It may be that you’ve identified a relationship between

entities.

In this case, you must associate the attribute with

only one entity, namely the parent entity, and

ensure that the relationship was previously

identified in Step 1.2.

Step 1.3 Identify the attributes associated with entities or relationships

Potential ProblemsPotential Problems((Attributes associated with more than one entity))

Page 27: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-27

For example, you may have identified the entities Branch and Staff with the following attributes:

The presence of the managerName attribute in Branch is intended to represent the relationship

Staff Manages Branch In this case, the managerName attribute should be

omitted from Branch and the relationship Manages should be added to the model

BranchBranch branchNo, street, city, state, branchNo, street, city, state, zipCode, zipCode, managerNamemanagerName

Staff Staff staffNo, staffNo, namename, position, salary, position, salary

Step 1.3 Identify the attributes associated with entities or relationships

Potential ProblemsPotential Problems((Attributes associated with more than one entity))

Page 28: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-28

BranchBranch

StaffStaffVideoVideoDirectorDirectorActorActorMemberMemberRentalAgreementRentalAgreementVideoForRentVideoForRent

branchNo, address (composite: street, city, state, ZipCode), branchNo, address (composite: street, city, state, ZipCode), telNo (multi-valued)telNo (multi-valued)staffNo, name, position, salarystaffNo, name, position, salarycatalogNo, title, category, dailyRental, pricecatalogNo, title, category, dailyRental, pricedirectorNamedirectorNameactorNameactorNamememberNo, name (composite: fName, lName), addressmemberNo, name (composite: fName, lName), addressrentalNo, dateOut, dateReturnrentalNo, dateOut, dateReturnvideoNo, availablevideoNo, available

StayHomeStayHome Attributes For Entities Attributes For Entities

Step 1.3 Identify the attributes associated with entities or relationships

Page 29: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-29

Attributes For RelationshipsAttributes For Relationships

You may have difficulty associating the attribute

representing the date a member is registered at a

branch, dateJoined, with a particular entity.

There are potentially three entities associated with this

attribute

Member, Branch, and Staff

However, this attribute cannot be associated with any of

these entities

Step 1.3 Identify and associate attributes with entities or relationships

Page 30: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-30

Attributes For RelationshipsAttributes For Relationships

A member can register at many branches, a member of

staff can register many members at many branches,

and a branch has many members.

The solution is to associate the dateJoined attribute with

the Registers ternary relationship,

which relates the Member, Branch, and Staff entities.

Step 1.3 Identify and associate attributes with entities or relationships

ERDERD

Page 31: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-31

Documenting AttributesDocumenting Attributes

Record the following information for each attribute:

Attribute name and description

Data type and length

Any aliases that the attribute is known by

Whether the attribute must always be specified

Allows or disallows nulls

Step 1.3 Identify and associate attributes with entities or relationships

Page 32: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-32

Documenting Attributes (Cont…)Documenting Attributes (Cont…)

Record the following information for each attribute: Whether the attribute is multi-valued Whether the attribute is composite

If so, which simple attributes make up the composite attribute

Whether the attribute is derived If so, how it should be computed

Default values for the attribute

Step 1.3 Identify and associate attributes with entities or relationships

Page 33: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-33

Step 1.4 Step 1.4 Determine Attribute Domain (Determine Attribute Domain ( 值域值域 ))

A domain is a set of values from which one or more

attributes draw their values

A domain specifies:

The set of allowable values for a given attribute

The size and format of a given attribute

Step 1.4 Determine attribute domains

Page 34: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-34

ExamplesExamples of Attribute Domain of Attribute Domain

The attribute domain of valid branch numbers A four-character, fixed-length string, with

the first character as a letterthe next three characters as digits in the range 000-

999

The attribute domain for valid telephone numbersA 10-digit string

Step 1.4 Determine attribute domains

Page 35: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-35

Document Attributes In Data DictionaryDocument Attributes In Data Dictionary

Multi-valued?Multi-valued?Composite?Composite?Derived? How?Derived? How?Default value?Default value?Constraint?Constraint?Key?Key?

Multi-valued?Multi-valued?Composite?Composite?Derived? How?Derived? How?Default value?Default value?Constraint?Constraint?Key?Key?

Step 1.3 Identify and associate attributes with entities or relationships

Attribute domain

Page 36: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-36

Step 1.5 Determine Candidate, Primary, and Step 1.5 Determine Candidate, Primary, and Alternate Key AttributesAlternate Key Attributes

Identifying candidate key(s) for an entity and then

selecting one to be the primary key.

Primary keys can never be null.

Remaining candidate keys are called alternate keys.

Document candidate, primary, and alternate keys

Step 1.5 Determine Candidate, Primary, and Alternate Key Attributes

ERDERD

Page 37: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-37

StayHomeStayHome ERD and Primary Keys ERD and Primary Keys

Step 1.5 Determine Candidate, Primary, and Alternate Key Attributes

Page 38: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-38

Document Candidate, Primary, and Document Candidate, Primary, and Alternate Keys in Data DictionaryAlternate Keys in Data Dictionary

Step 1.5 Determine Candidate, Primary, and Alternate Key Attributes

Multi-valued?Multi-valued?Composite?Composite?Derived? How?Derived? How?Default value?Default value?Constraint?Constraint?

Multi-valued?Multi-valued?Composite?Composite?Derived? How?Derived? How?Default value?Default value?Constraint?Constraint?

Page 39: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-39

Step 1.6 Step 1.6 Check Model Supports User TransactionsCheck Model Supports User Transactions

The objective of this step:The objective of this step:

Check the ER model to ensure that the model Check the ER model to ensure that the model

supports the required transactions.supports the required transactions.

Using the ER model and data dictionary to perform the Using the ER model and data dictionary to perform the

transactions manually.transactions manually.

Two possible approaches: Two possible approaches:

(1)(1) Describing the transactionDescribing the transaction

(2)(2) Using transaction pathwaysUsing transaction pathways

Step 1.8 Check Model Supports User Transactions

Page 40: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-40

Describing the TransactionDescribing the Transaction

Check that all the information (entities, relationships, and their attributes) required by each transaction is provided by the model.

Example:

Transaction : List the name of each manager at each branch, ordered by branch numberThe name of each manager is held in the Staff entityBranch details are held in the Branch entity. We can use the Staff-Manages-Branch relationship to

find the name of each manager for each branch.

Page 41: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-41

Using Transaction PathwaysUsing Transaction Pathways

Validating a data model against the required

transactions involves representing the pathway taken

by each transaction directly on the ER diagram.

An example of this approach using data queries is listed

in Section 4.4.4

Clearly, the more transactions that exist, the more

complex this diagram would become. So, for readability

you may need several such diagrams to cover all the

transactions.

Page 42: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-42

Transaction Requirements For Data QueriesTransaction Requirements For Data Queries

Data Queries (Section 4.4.4 on Page 76)m) List the details of branches in a given cityn) List the name, position, and salary of staff at a given branch,

ordered by staff nameo) List the name of each Manager at each branch, ordered by branch

numberp) List the title, category, and availability of all videos at a specified

branch, ordered by category.q) List the title, category, and availability of all videos at a specified

branch for a given actor’s name, ordered by categoryr) List the title, category, and availability of all videos for a given

director’s name at a specified branch, ordered by title.s) List the details of all videos a specified member currently has on

rentt) List the details of copies of a given video at a specified branch.……………

Step 1.8 Check Model Supports User Transactions

Page 43: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-43

Using Using Transaction Transaction PathwaysPathways

Step 1.8 Check Model Supports User Transactions

actor

many videos

many video copies

many branches

Page 44: Chapter 8 Conceptual Data Modeling ( 概念性的資料建模 ). 8-2 Chapter Outline   Three main phases of database design   Use ER modeling technique to build an

8-44

Step 1.7 Step 1.7 Check Model With UsersCheck Model With Users

Review the ER model with the users to ensure that the

model is a ‘true’ representation of the data

requirements of an organization (or the part of an

organization) to be supported by the database.