database design - knuwidit.knu.ac.kr/~kiyang/teaching/db/s17/lectures/4.db-dbdesign.pdf · the goal...

34
Database Design Database Development Lifecycle

Upload: others

Post on 03-Oct-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Design

Database Development Lifecycle

Page 2: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Why Database? From Data …

Simple dumping of data on the storage medium provides little value.

Database System 2

id name address country pay due100 J. Rodney 12 High Rd., Leeds UK 33.75

523 E. Hoover 52 Ln. Muncie, IN USA 0

800 M. Old Box. 9, Miami, FL USA 12.50

product_id title cost sale price123-19-20 Joy of Living 12.50 19.25

169-15-34 Learning Judo 20.00 25.00

354-90-33 Your Dream Home 18.25 24.25

PRODUCT

CUSTOMER

SALE

id zone product_id quantity total price100 UK 123-19-20 2 38.50

523 USMW 354-90-33 1 24.25

100 UK 169-15-34 1 25.00

800 USSE 123-19-20 1 19.25

Page 3: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

The goal is not just storage of data, but ultimately the extraction of information to support decision making by key people and groups in the organization. Data Information (e.g. reports, tabulations, graphs) Decisions

Sales of Titles in the UK Zone

0

10

20

30

40

50

Joy of Living Learning Judo

Titles

To

tal S

ale

s (

$)

Database System 3

- Summarized fact or information -

* In the UK ZONE, Joy of Living had a sale of

$38.50, and Learning Judo had a sale of $25.

** UK ZONE had the total sale of $63.50, USMW

had $24.25, and USSE had $19.25.

Title UK USMW USSE total

Joy of Living 38.50 19.25 57.75

Learning Judo 25.00 25.00

Your Dream Home 24.25 24.25

63.50 24.25 19.25 107.00

SALE by Zone**

*

Why Database? … Towards Information

Page 4: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database System 4

Database Systems: Design, Implementation, & Management: Rob & Coronel

(DBMS)

Why Database? … For Decision Making

Page 5: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Design: Intro

Database SystemProvides data collection 수집, storage 저장, and retrieval 검색

Composed of people, hardware, software, database(s), procedures, and application programs

Database DesignFoundation of a successful database system 휼륭한 DB system의 기반

Should promote

• Data integrity 데이터 무결성

• Prevent data redundancies 반복 & anomalies 오류

Must yield a database that

• is efficient in its provision of data access 효율적인 데이터 접근

• meet the objectives of the database system and serves the needs of its users DB시스템의 목적과 이용자의 요구 만족

Database Design 5

Page 6: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Data Redundancy (데이터의반복성)

Database Systems: Design, Implementation, & Management: Rob & Coronel

Database Design 6

Page 7: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Data Anomaly 데이터의오류

Database System 7

Update anomalies 수정오류

- Data inconsistencies resulting from “islands of information” problem

Insertion Anomalies 삽입오류

- Creation of bogus record when adding new data (e.g. new agent)

Deletion Anomalies 삭제오류

- Unintended deletion of related data (e.g. agent data when deleting customer)

Database Systems: Design, Implementation, & Management: Rob & Coronel

Page 8: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Development System Construction 시스템 구축

System Analysis 시스템 분석

• Establish the need and extent of an information system

System Development 시스템 개발

• Design & implement the information system

Database Construction DB 구축

Planning & Analysis 기획분석

Analyze data environment & Define database objectives

Database Development

• Design 설계

→ Construct a data model & establish data management processes

• Implementation 구현

→ Create the storage structure (e.g., tables) & user interface for data management

• Maintenance 유지보수

→ (corrective & adaptive) modification, backup & recovery

Database Design 8

Page 9: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Development Lifecycle

Planning & Analysis

기획분석

Design

개념 설계

Implementation

구현

Maintenance

정비

Database Objectives

Business Rules Data Model

DBMS Tables User Interface SQL Queries

Modification Backup & Recovery Security

Database Design 9

Page 10: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Lifecycle: Planning & Analysis

Define Database Objectives DB목적설정

What will the database (DB) do? What tasks 업무/작업will the DB support?

→ Data Entry, Update, Search

What information will the DB provide?→ Q & A

← Study the DB environment

How does the business operate?

Who are the players?

How does the information flow?

← Examine the data

Database Design 10

Planning & Analysis Database Design Implement Maintain

Sample Q&A: Recipe Database

Query Result

recipe name recipe info (ingredients, steps, …)

ingredients

recipe names recipe info

main ingredient (meat, fish, …)

recipe type (diet, diabetic, …)

recipe category (soup, desert, …)

budget, time

Page 11: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Lifecycle: Database Design

Create a Database Model DB 모델 제작

→ that can achieve the database objectives

1. Conceptual Design – ER Modeling

2. Logical Design – Relational Schema & Normalization

3. Physical Design – Schema into DBMS (Table Creation)

What is a Database Model?

→ Abstract data structure of the real-world items

실제 항목의 추상적인 data 구조

← Need to understand how business works & what role data plays

Database Design 11

Planning & Analysis Database Design Implement Maintain

Page 12: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Design: Conceptual Design

Conceptual Design Steps1. Enumerate the Business Rules

How does the business work?

2. Construct the Data Model Identify Entities, Relationship, Attributes & draw an ER Diagram

3. Verify the Data Model Does the data model support the fulfillment of database objectives?

Database Design 12

Planning & Analysis Database Design Implement Maintain

Page 13: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Conceptual Design: Business Rules

What 조직 내 정확한 업무 기술

Brief, precise, and unambiguous descriptions of operations in an organization• Based on policies, procedures, or principles within a specific organization

Why 정확한 data model 설계를 위하여

Promote creation of an accurate data model← Enhance understanding & facilitate communication

How (sources)Interviews, Documentation, Observation

Examples

• A painter can draw many paintings. A painting is drawn by a single painter.

• A teacher can teach 0 to 6 courses per semester.• A course is taught by a single teacher.

• A student must take at least 1 and at most 6 courses.• A course can have 10 to 40 students.

PAINTER PAINTINGdraws1 M

TEACHER COURSEteaches1 M

STUDENT

takes

M

N

Database Design 13

Planning & Analysis Database Design Implement Maintain

Page 14: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Conceptual Design: Data Modeling

What is Data Modeling?A model is a representation of reality

that retains only carefully selected essential details.

Logical organization of datafor optimum information extraction and data manipulation

Why Model? 주요한 data 요소들을 이해하고 인식하기 위하여

To understand and identify essential data elements

How?Identify Entities 개체, Attributes 속성, & Relationships 관계

STUDENT

TEACHER

ID

GPA

Major

Name

email

Office

Database Design 14

Planning & Analysis Database Design Implement Maintain

Page 15: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Design: Relational Schema

Specification of the overall structure/organization of a database

Relations Entities w/ Attributes

Primary key• Unique identifier

Foreign key PK of related table

Relationship type (connectivity) 1:M, M:N, 1:1

Database Design 15

Planning & Analysis Database Design Implement Maintain

https://www.coursera.org/learn/analytics-mysql/lecture/hDLIS/relational-schemas

Page 16: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Design: Data Dictionary

Detailed description of a data model Lists attribute names and characteristics for each table in the database Blueprint & documentation of a database

Database Design 16

Planning & Analysis Database Design Implement Maintain

Database Systems: Design, Implementation, & Management: Rob & Coronel

Page 17: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Database Design: Lifecycle

1. Define Database Objectives DB 목적 설정

What information will the database provide?

2. Examine the Data Environment data 환경 조사

How does the business work & what data are used?

3. Construct the Data Model data모델 구축

a. Enumerate the Business Rule.

b. Identify Entities & Relationships between them.

c. Define Attributes (and primary & foreign keys) for each entity

d. Create an initial E-R diagram

e. Normalize the entities 개체 정규화

Process for evaluating & designing good table structures

4. Verify the Data Model data모델 확인

Does the data model support the database objectives?

If not, modify the Data Model

Database Design 17

Page 18: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Data Model: University Example

Database Design 18

Page 19: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Appendix

Database System 19

Page 20: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

DB Design - Conceptual Design: Data Analysis & Requirements

Discover the data that can be transformed into desired information Information Need

What kind of information is needed?→ what output (queries & reports) must be generated by the system?

User Characteristics Who will use the information? How will information be used?

Information Source Where is the information to be found? How is the information to be extracted?

Information Constitution What data elements are needed to produce the information? What are the data attributes and relationships? What data transformations are to be used to produce the information?

Develop a thorough understanding of the company’s data Flow, uses, characteristics

Data Flow Diagram

Data sources Interviews, direct observation Business Rules

Narrative description of policy & procedures

Database System 20

Planning & Analysis Database Design Implement Maintain

Page 21: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Conceptual Design – ER Modeling: Business Rules What: Brief, precise, and unambiguous descriptions of operations in an organization

• based on policies, procedures, or principles within a specific organization• help to create and enforce actions within that organization’s environment• apply to any organization that stores and uses data to generate information

Why: Enhance understanding & facilitate communication• Standardize company’s view of data• Constitute a communications tool between users and designers • Allow designer to understand business process as well as the nature, role, and scope of data

Promote creation of an accurate data model

How (sources)Interviews• Company managers, Policy makers, Department managers, End users

Written documentation• Procedures, Standards, Operations manuals

Observation• Business operations

Examples• A painter can draw many paintings. A painting is drawn by a single painter.• A teacher can teach 0 to 6 courses per semester. A student must take at least 1 and at most 6

courses.

Database System 21

Planning & Analysis Database Design Implement Maintain

Page 22: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

E-R model is verified against proposed system processes.

Corroboration that intended processes can be supported by the database model

Careful reevaluation of the entities and detailed examination of attributes

Verification of business transactions as well as system and user requirements

May reveal additional entity and attribute details.

Verification process is iterative.1. identify ER model’s central entity

2. identify modules/subsystems & components

3. identify transaction requirements update/insert/delete/query/report

user interface

4. verify all processes against ER model

5. make necessary changes

6. repeat steps 2 through 5

Database System 22

Database Systems: Design, Implementation, & Management: Rob & Coronel

Conceptual Design – ER Modeling: E-R Model Verification

Planning & Analysis Database Design Implement Maintain

Page 23: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

What are the advantages & disadvantages?Cost• purchase, maintenance, operational, training, etc.

Features & Tools• ease-of-use, performance, DB administration, etc.

• application development tools

DB model• hierarchical, RDB, Object-oriented, etc.

Portability• platform, O/S, SQL

Hardware requirement• processor, RAM

Database System 23

DB Design - Conceptual Design: DBMS Selection

Planning & Analysis Database Design Implement Maintain

Page 24: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Logical DesignTranslate conceptual design into internal model that maps objects in model to specific DBMS constructs• From software independent to software dependent

Detailed & functional descriptions of system components• Specify system processes and I/O.

• e.g., table design, attribute definitions, access restrictions

Physical DesignSelect the data storage and data access characteristics of the database• More important in older hierarchical and network models

• Becomes more complex when data are distributed at different locations

Can affect the database performance• e.g. storage media, buffer size, etc.

Designers favor software that hides physical details

Database System 24

DB Design: Logical & Physical Design

Planning & Analysis Database Design Implement Maintain

Page 25: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

DB Lifecycle - Analysis: Feasibility Analysis

Technological FeasibilityWhat hardware, software, and additional resources would be needed?

What is available in-house? What has to be purchased?

How will the new system be integrated?

Operational FeasibilityWho will design the system?

Who will maintain the system?

Who will do training or help-desk support?

Can the available personnel provide the time? New personnel necessary?

Economic FeasibilityExpected cost of the overall project ($)?• Software, hardware, application development, staff-time

• Hidden cost (unforeseen)

Other costs• What is the competition/comparable unit doing?

• Would data sharing among departments lead to additional expenses?

Benefits • How soon expected?

Database System 25

Planning & Analysis Database Design Implement Maintain

Page 26: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

DB Lifecycle - Design: Data Modeling

What is Data Modeling?A model is a representation of reality that retains only carefully selected essential details.

Logical organization of data for optimum information extraction and data manipulation

Why Model?To understand and identify essential data elements

To produce a representation that can be transformed into a schema

How?Data modeling involves• identifying entities, attributes, and relationships

Database System 26

Planning & Analysis Database Design Implement Maintain

Page 27: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

Exercises

Page 28: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

BBB

AAA BBBdoesM N

one AAA does many BBB

one BBB is done by many AAA

CCC has1 M

a CCC has several BBB

each BBB belongs to one CCC

a, an, each one 1

some, several many M

DDD AAAowns1 1

a DDD owns one AAA

each AAA is owned by one DDD

does

M

N

ERD Tips

Page 29: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

CLASS

PROFESSOR STUDENTteachesM N

A professor teaches many students.

A student is taught by several professors.

PROFESSOR teaches1 M

A professor teaches many classes.

A class is taught by a single professor.

STUDENT CLASSenrollsM N

A students enrolls in many classes.

A class has many students.

enrollsMN

STUDENT

ERD example

Page 30: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

PROFESSOR STUDENTteachesM N

PROFESSOR CLASS STUDENTteaches has

Crow’s Foot ERD

PROFESSOR CLASS STUDENT

Chen ERD

teaches has1 NM M

ERD example

Page 31: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

PROFESSOR CLASS STUDENTteaches has1 NM M

Business Rules

A professor can teach many classes. A class is taught by one

professor.

A student can take many classes. A class can have many students.

A course can generate many classes. A class is generated by one

course.

COURSE

generates

1

M

ERD Example

Page 32: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

1. Draw an E-R Diagram of the data model described by the business rules below.

One region can be the location for many stores. Each store is located in only one region.

Each store employs one or more employees. Each employee is employed by one store.

A job can be assigned to many employees.-- e.g., The "Sales Representative" job can be assigned to more than one employee at a time.

Each employee can have only one job assignment.

Data Modeling Exercises

1. Draw an E-R Diagram of the data model described by the business rules below.

One region can be the location for many stores. Each store is located in only one region.

Each store employs one or more employees. Each employee is employed by one store.

A job can be assigned to many employees.-- e.g., The "Sales Representative" job can be assigned to more than one employee at a time.

Each employee can have only one job assignment.

1. Draw an E-R Diagram of the data model described by the business rules below.

One region can be the location for many stores. Each store is located in only one region.

Each store employs one or more employees. Each employee is employed by one store.

A job can be assigned to many employees.-- e.g., The "Sales Representative" job can be assigned to more than one employee at a time.

Each employee can have only one job assignment.

REGION

EMPLOYEEemployees

M

is location for

STORE

M1

1

JOB

1

M

is assigned to

Database Design 32

Page 33: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

2. Identify the business rules and draw an E-R diagram of the situation described below.

For each professor, there may be multiple advisees. A professor teaches many classes and a class is taught by one professor.

Data Modeling Exercises

PROFESSOR CLASSteaches

advises

STUDENT

M

1

1

M

Business Rules

A professor can advise many students.

A student is advised by one professor.

A professor can teach many classes.

A class is taught by one professor

Database Design 33

Page 34: Database Design - KNUwidit.knu.ac.kr/~kiyang/teaching/DB/s17/lectures/4.DB-DBDesign.pdf · The goal is not just storage of data, but ultimately the extraction of information to support

3. Create a data model (i.e. ERD) for the school database described below.

DB will keep track of advising and class information. DB should provide following information.

- The list of students advised for a given year & dates of advising sessions for each students

- Course listing for each year & student grades for each class

Data Modeling Exercises

PROFESSOR CLASSteaches

advises

STUDENT

M

1

1

M

Business Rules

A professor can advise many students. A student is advised by one professor.

A professor can teach many classes. A class is taught by one professor.

A student can take many classes. A class can have many students.

A course can generate many classes. A class is generated by one course.

A professor can meet many times with an advisee. A student can meet many times with the advisor.

COURSE

takes

3. Create a data model (i.e. ERD) for the school database described below.

DB will keep track of advising and class information. DB should provide following information.

- The list of students advised for a given year & dates of advising sessions for each students

- Course listing for each year & student grades for each class

generates

1

M

3. Create a data model (i.e. ERD) for the school database described below.

DB will keep track of advising and class information. DB should provide following information.

- The list of students advised for a given year & dates of advising sessions for each students

- Course listing for each year & student grades for each class

Database Design 34

M

M

1

1

ADVISING

1

1

M

M

3. Create a data model (i.e. ERD) for the school database described below.

DB will keep track of advising and class information. DB should provide following information.

- The list of students advised for a given year & dates of advising sessions for each students

- Course listing for each year & student grades for each class

M

N

Sample DB

ENROLL