ระบบฐำนข้อมูล (database system)mit.wu.ac.th/mit/images/editor/files/dbs...

Post on 23-Jun-2020

0 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Connolly, Thomas and Begg, Carolyn. 2010. Database Systems: A

Practical Approach to Design, Implementation, and Management.

5th Ed. Pearson Education. ดร. สลล บญพรหมณ ส ำนกวชำสำรสนเทศศำสตร

Normalization

ITM-661 ระบบฐำนขอมล (Database system)

2

"...คนเรำถำพอในควำมตองกำรกมควำมโลภนอย เมอมควำมโลภ

นอยกเบยดเบยนคนอนนอย ถำทกประเทศมควำมคด คด-อนน

ไมใชเศรษฐกจ มควำมคดวำท ำอะไรตองพอเพยง หมำยควำม

วำ พอประมำณ ไมสดโตง ไมโลภอยำงมำก คนเรำกอยเปนสข

..."

พระราชด ารสในพระบาทสมเดจพระเจาอยหว

พระราชทานเนองในโอกาสวนเฉลมพระชนมพรรษา

ณ ศาลาดสดาลย สวนจตรลดา พระราชวงดสต

๔ ธนวาคม ๒๕๔๐

Objectives

The purpose of normalization.

How normalization can be used when designing a relational database.

The potential problems associated with redundant data in base relations.

The concept of functional dependency, which describes the relationship between attributes.

The characteristics of functional dependencies used in normalization.

3

Objectives

How to identify functional dependencies for a given relation.

How functional dependencies identify the primary key for a relation.

How to undertake the process of normalization.

How normalization uses functional dependencies to group attributes into relations that are in a known normal form.

4

Objectives

How to identify the most commonly used normal forms, namely First Normal Form (1NF), Second Normal Form (2NF), and Third Normal Form (3NF).

The problems associated with relations that break the rules of 1NF, 2NF, or 3NF.

How to represent attributes shown on a form as 3NF relations using normalization.

5

Purpose of Normalization

Normalization is a technique for producing a set of suitable relations that support the data requirements of an enterprise.

Characteristics of a suitable set of relations include:

The minimal number of attributes necessary to support the data requirements of the enterprise;

attributes with a close logical relationship are found in the same relation;

minimal redundancy with each attribute represented only once with the important exception of attributes that form all or part of foreign keys.

6

7

The benefits of using a database that has a suitable set of relations is that the database will be:

easier for the user to access and maintain the data;

take up minimal storage space on the computer.

How Normalization Supports Database Design

8

9

Major aim of relational database design is to group attributes

into relations to minimize data redundancy.

Potential benefits for implemented database include:

Updates to the data stored in the database are achieved

with a minimal number of operations thus reducing the

opportunities for data inconsistencies.

Reduction in the file storage space required by the base

relations thus minimizing costs.

Problems associated with data redundancy are illustrated by

comparing the Staff and Branch relations with the StaffBranch

relation

Data Redundancy and Update Anomalies

10

StaffBranch relation has redundant data; the details of a branch are repeated for every member of staff.

11

In contrast, the branch information appears only once for each branch in the Branch relation and only the branch number (branchNo) is repeated in the Staff relation, to represent where each member of staff is located.

12

Relations that contain redundant information may potentially suffer from update anomalies.

Types of update anomalies include

Insertion

Deletion

Modification

13

Functional Dependencies (FD)

Important concept associated with normalization.

Functional dependency describes relationship between attributes.

For example, if A and B are attributes of relation R, B is functionally dependent on A

(denoted A B),

if each value of A in R is associated with exactly one value of B in R.

14

คณสมบตของ FD

Property of the meaning or semantics of the attributes in a relation.

Diagrammatic representation.

The determinant of a functional dependency refers to the attribute or group of attributes on the left-hand side of the arrow.

ตวอยาง

15

16

Consider the values shown in staffNo and sName attributes of

the Staff relation

Based on sample data, the following functional dependencies

appear to hold.

staffNo → sName

sName → staffNo

Example FD that holds for all time

17

However, the only functional dependency that remains true for all possible values for the staffNo and sName attributes of the Staff relation is:

staffNo → sName

18

ตวอยาง

กำรเปนทปรกษำ (รหส, ชอ, นำมสกล, GPAX, หลกสตร, รหสอำจำรย, ชออำจำรย, หองท ำงำน, โทรศพท)

19

การเขยน FD

SSN ENAME

PNUMBER PNAME, PLOCATION

SSN + PNUMBER HOURS

SSN PNUMBER HOURS ENAME PNAME PLOCATION

EMP_PROJ (SSN, PNUMBER, HOURS, ENAME, PNAME, PLOCATION)

แบบท 1

แบบท 2

20

Determinants should have the minimal number of attributes necessary to maintain the functional dependency with the attribute(s) on the right hand-side.

This requirement is called full functional dependency.

21

Full functional dependency indicates that

if A and B are attributes of a relation,

B is fully functionally dependent on A, if B is functionally dependent on A, but not on any proper subset of A.

22

หรอ

A functional dependency x y is partial dependency if

there is some attribute A X that can be removed from X and dependency will still hold.

That is A, A X , (X - {A}) Y

23

ตวอยาง Full FD

Exists in the Staff relation

staffNo, sName → branchNo

True - each value of (staffNo, sName) is associated with a single value of branchNo.

However, branchNo is also functionally dependent on a subset of (staffNo, sName), namely staffNo.

Example above is a partial dependency.

24

Main characteristics of FD used in normalization:

There is a one-to-one relationship between the attribute(s) on the left-hand side (determinant) and those on the right-hand side of a functional dependency.

Holds for all time.

The determinant has the minimal number of attributes necessary to maintain the dependency with the attribute(s) on the right hand-side.

25

ค ำแนะน ำ

ในตำรำงทม attribute จ ำนวนมำก กำรหำ FD จะยำกขน รวมทงกำรเขยน FD จะดยำกจงใหใชกำรเขยนแบบท 2 เพรำะพจำรณำงำยกวำ ไมสบสน

26

Identifying Functional Dependencies

Identifying all FD between a set of attributes is relatively simple if the meaning of each attribute and the relationships between the attributes are well understood.

This information should be provided by the enterprise in the form of discussions with users and/or documentation such as the users’ requirements specification.

27

Identifying Functional Dependencies (ตอ)

if

the users are unavailable for consultation and/or

the documentation is incomplete

then

depending on the database application it may be necessary for the database designer to use their common sense and/or experience to provide the missing information.

28

สรปการเขยน FD

ขอมลจำกเอกสำรทรวบรวมมำเพอออกแบบฐำนขอมลวำประกอบไปดวยขอมลอะไร และขอมลสมพนธกนหรอไม อยำงไร

ผใช(user)บอกใหทรำบ

ประสบกำรณหรอวจำรณญำณของผออกแบบ

สำมญส ำนกของผออกแบบ บำงครงเรำสำมำรถระบไดเพรำะเปนควำมสมพนธท “ใครๆกร” เชน หมำยเลขโทรศพททใช

ตดตอลกคำยอมซ ำได

29

ตวอยาง

Examine semantics of attributes in StaffBranch relation.

Assume that position held and branch determine a member of staff’s salary.

30

FD ของ StaffBranch relation คอ

staffNo → sName, position, salary, branchNo, bAddress

branchNo → bAddress

bAddress → branchNo

branchNo, position → salary

bAddress, position → salary

31

Identifying the PK for a Relation using FD

Main purpose of identifying a set of FD for a relation is to specify the set of integrity constraints that must hold on a relation.

An important integrity constraint to consider first is the identification of candidate keys, one of which is selected to be the primary key for the relation.

32

StaffBranch relation has 5 FD

staffNo → sName, position, salary, branchNo, bAddress

branchNo → bAddress

bAddress → branchNo

branchNo, position → salary

bAddress, position → salary

The determinants are staffNo, branchNo, bAddress, (branchNo, position), and (bAddress, position).

33

To identify all candidate key(s), identify the attribute (or group of attributes) that uniquely identifies each tuple in this relation.

All attributes that are not part of a candidate key should be functionally dependent on the key.

The only candidate key and therefore primary key for StaffBranch relation, is staffNo, as all other attributes of the relation are functionally dependent on staffNo.

34

ค าแนะน า

FD ใชในกำรท ำ normalization ตงแตระดบท 2 เปนตนไป และในกำรท ำ normalization แตละระดบจะมประเดนทตองตรวจควำมเกยวของของ attribute ตำงกน

ดงนนจงไมควรรบเขยน FD ในทกประเดนเพรำะจ ำนวน attribute ยงมจ ำนวนมำกอย ใหแสดงเฉพำะประเดนทใชในกำรท ำ normalization นนๆ

35

ค าแนะน า

ตรวจสอบจ ำนวน attribute ใน FD วำตองไมตกหลนจำกตำรำงทตรวจสอบอย ยงตรวจสอบเรำจะไดตำรำงเพมขน และขนำดตำรำงจะเลกลง

ในกำรเขยน FD ไมควรเขยน non-key attribute ซ ำกบ FD อนโดยไมเกดประโยชน เพรำะจะท ำใหสบสนโดยไมจ ำเปน

36

3. Normalization

Normalization is a technique for producing a set of suitable

relations that support the data requirements of an

enterprise.

As normalization proceeds, the relations become

progressively more restricted (stronger) in format and also

less vulnerable to update anomalies.

37

The Process of Normalization

Formal technique for analyzing a relation based on its primary key and the functional dependencies between the attributes of that relation.

Often executed as a series of steps. Each step corresponds to a specific normal form, which has known properties.

38

How Normalization Supports DB Design

39

The Process of Normalization

40

41

Unnormalized Form (UNF)

A table that contains one or more repeating groups.

To create an unnormalized table

Transform the data from the information source (e.g. form) into table format with columns and rows.

42

43

4. First Normal Form (1NF)

A relation is said to be in the first normal form if it contains no repeating group.

A table in which the intersection of every column and record contains only one value.

44

ถำตำรำงนนไมมกำรเกบขอมลมำกกวำ 1 ชด (repeating group) หรอขอมลทเกบมคำเพยงคำเดยว (single value) หรอ

ถำในทกชอง (intersection คอจดทแถวกบคอลมนตดกน อำจเรยกวำ cell หรอชอง) เกบขอมลเพยงคำเดยว

45

46

UNF to 1NF

Nominate an attribute or group of attributes to act as the key for the unnormalized table.

Identify the repeating group(s) in the unnormalized table which repeats for the key attribute(s).

47

การแปลง UNF เปน 1NF

Remove the repeating group by

Entering appropriate data into the empty columns of rows containing the repeating data (‘flattening’ the table).

Or by

Placing the repeating data along with a copy of the original key attribute(s) into a separate relation.

48

ตวอยาง

ลองพจารณาตารางนวามคณสมบต First normal form หรอไม

49

แยกคาทซ าออกเปนแถวหรอ tuple ใหมซงผลทไดคอ

50

จำกกำรแยกแถวใหมนนจะท ำใหในบำงเซลยงไมมขอมล จงตองเตมขอมลใหครบถวน กำรท ำแบบนเรยกวำกำรท ำ table flattening

51

แตจะพบวำ Primary key เดมนนไมสำมำรถใชไดอกตอไป เพรำะไมมคณสมบต Uniqueness หรอคำทไมซ ำ จงตองพจำรณำ Key ใหม ในทนจะใช SID มำเปน key

52

จงไดตารางสดทายทมคณสมบตของ 1NF ทเขยนไดเปน

53

ตวอยำง จงตรวจสอบและแกไขตำรำง Enrolment ใหมคณสมบต 1NF

54

ตาราง Enrollment นไมมคณสมบตของ 1NF

55

กำรแกไขเพอท ำให relation นมคณสมบต 1NF ท ำไดโดยกำรแยกคำทมมำกกวำ 1 คำนนออกมำเปนแตละ tuple หรอแยกออกมำเปนคำในแถวยอยๆ และตองเตมคำในแถวใหครบ

56

เมอแกไขแลวจะเหนวำ Course_ID ซงเปน Key เดมเนองจำกมคณสมบตทใหคำไมซ ำ (Uniqueness) จะใชไมไดอกตอไป จงตองพจำรณำ Primary key ทเหมำะสมใหมดวยในกรณนจงเพม Course_ID เปน key อก 1 attribute โดยจะได relation ทมลกษณะดงน

57

ตวอยาง จงตรวจสอบและแกไขตำรำง Project ใหมคณสมบต 1NF

58

พบวำ pno ซงเดมใชเปน primary key ไมสำมำรถใชเปน key ได อกตอไปเพรำะมหลำยบรรทดทใชคำของ pno เหมอนกน

59

60

การแกไขตารางประกอบดวยขนตอนดงน

1) แยกคำทใสมำกกวำ 1 คำออกมำใสในบรรทดใหม โดยจดให ใสเซลละ 1 คำเทำนน

2) เตมคำในสวนทเกยวของในเตมบรรทด ส ำหรบในกรณน เมอเพมบรรทดใหมใหใสคำของ Emp_num และ Emp_name ลงไปในบรรทดใหมดวย

3) ก ำหนด primary key ในตำรำงทแกไขแลว

61

สรป

ขนตอนกำรแกไขใหตำรำงมคณสมบต 1NF มดงน

1) ตรวจสอบวำ repeating group หรอไม หำกไมมถอวำเปน 1NF โดยใช key เดมได แตถำม repeating group ให ด ำเนนกำรตอไป

2) ท ำให attribute ทเกบคำมำกกวำ 1 คำเกบไดเพยงคำเดยวโดยเกบแยกบรรทดละ 1 คำ ในกำรท ำเชนนจะตองเตมคำเดมลงในบรรทดใหมใหครบถวนดวย กำรท ำเชนนมวำ table flattening

3) ก ำหนด primary key ของตำรำงใหม

62

63

5. Second Normal Form (2NF)

Based on the concept of full functional dependency.

Full functional dependency indicates that if

A and B are attributes of a relation,

B is fully dependent on A if B is functionally dependent on A but not on any proper subset of A.

64

A relation is in 2NF if it has been placed in 1NF, and if every data item in the entity is fully functionally dependent on the primary key.

A functional dependency x y is partial dependency if

there is some attribute A X that can be removed from X and dependency will still hold.

That is for some A X , (X - {A}) Y

65

ตวอยาง

ถา X = {รหสวชา, รหสผสอน} และ

Y = {หนวยกต, ชอวชา}

X Y

รหสวชา, รหสผสอน หนวยกต, ชอวชา

รหสวชา หนวยกต, ชอวชา

ดงนน สรปวา

รหสวชา, รหสผสอน หนวยกต, ชอวชา

มความสมพนธแบบ partial dependency

66

การแปลง 1NF ใหเปน 2NF

1) Identify the PK for the 1NF relation.

2) Identify the FD in the relation.

3) If partial dependencies exist on the primary key remove them by placing them in a new relation along with a copy of their determinant.

4) สรปตำรำงทมคณสมบต 2NF

จงพจารณาตารางตอไปน

67

Business rules: 1) แตละวชำมผสอนไดเพยงคนเดยว 2) ผสอนแตละคนสอนไดมำกกวำ 1 วชำ 3) รหสวชำจะซ ำกนไมได แตชอวชำอำจซ ำกนได

68

69

70

ขนตอนการท าใหเปน 2NF ประกอบดวย

ข นตอนท 1

เปนกำรขจดกลมของขอมลทซ ำ ซงจะไดเปนตำรำงท

ประกอบดวย Attribute ทมคำๆเดยวในทกcellของตำรำง (ท ำ

ใหเปน 1NF) และระบ primary key

71

ข นตอนท 2

เปนกำรตรวจสอบควำมสมพนธระหวำง Key attribute ซงอำจมำจำก attribute มำกกวำ 1 attribute (หรอทเรยกวำ Compound key) กบ attribute ทเหลอในตำรำงนนวำตองเปนกำรขนอยแกกนแบบครบถวน (Fully dependency) ไมใชแบบกำรขนแกกนเพยงบำงสวน (Partially dependency)

เขยน FD1

72

ข นตอนท 3

ส ำหรบ FD ทแสดงใหเหนวำเกด partial participation ใหแปลงเปนตำรำง

ใหม

FD ของ primary key แรกนนจะตองเหลอ non-key attribute เฉพำะท

เปน full-functionally dependence เทำนน

73

ขนตอนท 4 สรปตำรำง

74

ตวอยาง

ตำรำง assignment วำมคณสมบต 2 NF หรอไม หำกไมม จงแกไข

75

Business rules

1) พนกงำนแตละคนสำมำรถท ำงำนในโครงกำรไดมำกกวำ 1 โครงกำร

2) ระยะเวลำทพนกงำนแตละคนท ำงำนในโครงกำรไมเทำนน แลวแตปรมำณงำน

3) แตละโครงกำรเปนงำนของลกคำบรษทเดยว และมพนกงำนทท ำงำนให โครงกำรนนมำกกวำ 1 คน

4) ลกคำแตละบรษทอำจมโครงกำรทจำงใหด ำเนนกำรมำกกวำ 1 โครงกำร

5) ชอของโครงกำรอำจซ ำกนได

76

การพจารณาประกอบดวยขนตอนดงน

1. ตรวจสอบคณสมบต 1NF

ตำรำงมคณสมบต 1NF และโครงสรำงดงน

77

2. เขยน FD หลก (FD1)

assignment (empid, empname, pno, pname, pcompany, day)

78

3. เขยน FD รอง

เนองจำกกำรท ำ second normal form เปนกำรตรวจสอบกำรขนอย

กบคย ทตองเปนกำรขนกบคยอยำงสมบรณ (Fully functionally

dependent) ไมใชกำรขนกบสวนใดสวนหนงของคย (Partially

dependent) ดงนนจงตองหำวำสวนใดสวนหนงของคยนน

สำมำรถบอกอะไรไดบำง

79

การเขยน FD รองของตาราง Assignment

assignment (empid, empname, pno, pname, pcompany, day)

80

4. สรปตารางทมคณสมบต 2NF

โดยพจำรณำจำก FD ทงหมด

81

82

ขอสงเกต

กำรตรวจสอบ 2NF เปนกำรตรวจเพอพจำรณำวำ primary key ทเลอกมำนนใหญเกนจ ำเปนหรอไม โดยกำรตงค ำถำมวำจ ำเปนตองใช attribute มำกๆมำเปน key หรอเปลำ ม attribute ใดทเมอน ำออกไปแลว key ยงคงควำมเปน key

หำก Attribute ทเลอกเปน key นนมเพยง 1 attribute ซงไมสำมำรถลดขนำดของ key ไดแลว กรณเชนนจงมคณสมบต 2NF อยแลว

83

ตวอยาง

Business rules 1) ชอนกศกษำไมซ ำกน 2) รหสวชำไมซ ำกน แตชอวชำอำจซ ำกนได 3) นกศกษำแตละคนลงทะเบยนเรยนไดหลำยวชำ 4) แตละวชำอำจมนกศกษำเรยนมำกกวำ 1 คน 5) แตละวชำมผสอนรำยเดยว 6) ชออำจำรยไมซ ำกน 7) อำจำรยแตละคนสอนไดมำกกวำ 1 วชำ

84

กำรพจำรณำประกอบดวยขนตอนดงน

1. ท ำใหตำรำง Enrolment มคณสมบต 1NF

2. เขยน FD1

ในกรณนคยคอซงจดไดวำเปน compound key หรอ concatenated key คอ (SName, CourseID)

3. เขยน FD รอง

จงตองพจำรณำในลกษณะทกชดในคยทเปนไปไดในทนมคยเปนไปได 3 ชดคอ

SName,

CourseID,

(Sname, CourseID)

4. สรปตำรำงทมคณสมบต 2NF

85

Business rules 1) นกศกษำแตละคนมอำจำรยทปรกษำไดเพยงคนเดยว 2) นกศกษำสมครท ำงำนไดไมเกน 3 บรษท 3) แตละบรษทมเจำหนำทตดตอเพยงรำยเดยว เปนไปไดทช อจนท.อำจเหมอนกน 4) แตละบรษทอำจเปดรบสมครมำกกวำ 1 ต ำแหนง 5) จ ำนวนรบในแตละต ำแหนงทบรษทเปดรบไมจ ำเปนตองเทำกน 6) อำจำรยทปรกษำแตละคนมโทรศพทหมำยเลขเดยว และก ำหนดหมำยเลขให

อำจำรยแตละคนไมซ ำกน 7) อำจำรยแตละคนสำมำรถมนกศกษำทตองดแลไดมำกกวำ 1 คน

86

กำรพจำรณำประกอบดวยขนตอนดงน

1. ท ำใหตำรำงใหมคณสมบต 1NF

2. เขยน FD1

3. เขยน FD รอง

4. สรปตำรำงทมคณสมบต 2NF

87

6. Third Normal Form (3NF)

Based on the concept of transitive dependency.

Transitive Dependency is a condition where

A, B and C are attributes of a relation such that if A B and B C,

then C is transitively dependent on A through B. (Provided that A is not functionally dependent on B or C).

88

A relation is in 3NF

iff

it is in 2 NF and no nonkey attribute is “transitively dependent” on the primary key.

An entity is said to be in the 3NF

if it has been placed in 2NF

and

if all fields which are not a part of PK are mutually independent;

that is, there are no transitive dependencies.

89

Transitive dependency คออะไร

x y is transitive dependency

iff

there is a set of attributes Z that is not a subset of any key of R,

and both X Z and Z Y hold.

KEYS R X

Y

Z

90

Transitive dependency

Emp_Dept (ENAME, SSN, BDATE, ADDRESS, DNUMBER, DNAME,

DMGRSSN)

Business rules 1) หมำยเลขประกนสงคมของพนกงำนแตละคนไมซ ำกน ถงแมชอพนกงำนอำจ

เหมอนกน 2) พนกงำนแตละคนท ำงำนอยในแผนกใดแผนกหนงเพยงแผนกเดยว 3) แตละแผนกมหวหนำแผนกคนเดยว

91

กำรแปลง 2NF ใหเปน 3NF

Identify the primary key in the 2NF relation.

Identify FD in the relation.

If transitive dependencies exist on the primary key remove them by placing them in a new relation along with a copy of their dominant.

92

ขนตอนกำรตรวจสอบและแกไข

1. พจำรณำวำตำรำงคณสมบต 2 NFหรอไม ท ำใหตำรำงใหมคณสมบต 1NF

เขยน FD1

เขยน FD รอง

สรปตำรำงทมคณสมบต 2NF

2. พจำรณำวำตำรำงคณสมบต 3 NFหรอไม พจำรณำตำรำงทตองตรวจสอบ

ระบ FD ทท ำใหเกด Transitive dependency และปรบแก FD ของตำรำงนน

เขยนโครงสรำงตำรำงจำก FD ใหมทงสวนทเกด Transitive dependency และ FD ของตำรำงทแกไข

น ำมำสรปรวมกบตำรำงทงหมด

93

1. พจำรณำวำตำรำงคณสมบต 2 NF หรอไม ท ำใหตำรำงใหมคณสมบต 1NF

เขยน FD1

เขยน FD รอง

สรปตำรำงทมคณสมบต 2NF

94

2. พจำรณำวำตำรำงคณสมบต 3 NF หรอไม พจำรณำตำรำงทตองตรวจสอบ

ระบ FD ทท ำใหเกด Transitive dependency และปรบแก FD ของตำรำงนน

เขยนโครงสรำงตำรำงจำก FD ใหมทงสวนทเกด Transitive dependency และ FD ของตำรำงทแกไข

น ำมำสรปรวมกบตำรำงทงหมด

สรป

95

ตำรำง 1NF

ตำรำง 2NF

ตำรำง 3NF

96

ตวอยำง จงตรวจสอบตำรำง staffBranch และท ำใหมคณสมบต3NF

Business rules 1) พนกงำนแตละคนจะท ำงำนในสำขำใดสำขำหนงเพยงสำขำเดยว 2) แตละสำขำอำจมพนกงำนประจ ำอยมำกกวำ 1 คน 3) แตละสำขำมหมำยเลขโทรศพทหมำยเลขเดยว 4) ถงแมพนกงำนท ำงำนในต ำแหนงเดยวกน เงนเดอนอำจแตกตำง

กนได

วธท า

97

1. พจำรณำวำตำรำงคณสมบต 2 NFหรอไม ท ำใหตำรำงใหมคณสมบต 1NF

เขยน FD1

เขยน FD รอง

สรปตำรำงทมคณสมบต 2NF

98

2. พจำรณำวำตำรำงคณสมบต 3 NF หรอไม พจำรณำตำรำงทตองตรวจสอบ

ระบ FD ทท ำใหเกด Transitive dependency และปรบแก FD ของตำรำงนน

เขยนโครงสรำงตำรำงจำก FD ใหมทงสวนทเกด Transitive dependency และ FD ของตำรำงทแกไข

น ำมำสรปรวมกบตำรำงทงหมด

99

สรป

ตำรำง 1NF

ตำรำง 2NF

ตำรำง 3NF

100

ตวอยำง จงตรวจสอบตำรำง Assignmentและท ำใหมคณสมบต3NF

Business rules

1) แตละโครงกำรมพนกงำนรบผดชอบมำกกวำ 1 คน

2) ระยะเวลำทพนกงำนแตละคนท ำงำนในแตละโครงกำรอำจตำงกนตำมปรมำณงำน

3) คำตอบแทนทพนกงำนไดรบขนอยกบควำมรบผดชอบในโครงกำร

4) พนกงำนแตละคนมต ำแหนงหรอบทบำทเดยว แตต ำแหนงหนงๆมพนกงำนได มำกกวำ 1 คน

วธท ำ

101

1. พจำรณำวำตำรำงคณสมบต 2 NFหรอไม ท ำใหตำรำงใหมคณสมบต 1NF

เขยน FD1

เขยน FD รอง

สรปตำรำงทมคณสมบต 2NF

102

2. พจำรณำวำตำรำงคณสมบต 3 NF หรอไม พจำรณำตำรำงทตองตรวจสอบ

ระบ FD ทท ำใหเกด Transitive dependency และปรบแก FD ของตำรำงนน

เขยนโครงสรำงตำรำงจำก FD ใหมทงสวนทเกด Transitive dependency และ FD ของตำรำงทแกไข

น ำมำสรปรวมกบตำรำงทงหมด

103

สรป

ตำรำง 1NF

ตำรำง 2NF

ตำรำง 3NF

ตวอยำง จงตรวจสอบและท ำใหมคณสมบต3NF

104

105

Business rules 1) ในกำรซอสนคำของลกคำแตละครงกระท ำโดยพนกงำนขำยเพยงรำยเดยว 2) ในแตละวนสำมำรถมพนกงำนท ำงำนมำกกวำ 1 คน 3) ในวนหนงๆลกคำทซ อสนคำแลวจะไมกลบมำซอซ ำ 4) ลกคำรำยเดมสำมำรถซอสนคำซ ำไดโดยไมจ ำเปนวำปรมำณกำรซอจะตอง

เทำกนทกครงทซ อคำนน 5) ลกคำไมจ ำเปนตองใชบรกำรผขำยรำยเดมเพอกลบมำซอสนคำใหม

วธท ำ

106

1. พจำรณำวำตำรำงคณสมบต 2 NFหรอไม ท ำใหตำรำงใหมคณสมบต 1NF

เขยน FD1

เขยน FD รอง

สรปตำรำงทมคณสมบต 2NF

107

2. พจำรณำวำตำรำงคณสมบต 3 NF หรอไม พจำรณำตำรำงทตองตรวจสอบ

ระบ FD ทท ำใหเกด Transitive dependency และปรบแก FD ของตำรำงนน

เขยนโครงสรำงตำรำงจำก FD ใหมทงสวนทเกด Transitive dependency และ FD ของตำรำงทแกไข

น ำมำสรปรวมกบตำรำงทงหมด

108

สรป

ตำรำง 1NF

ตำรำง 2NF

ตำรำง 3NF

top related