Normal Forms GROUP #6 # Nititorn Boonpakdee Orapan Tiemsaku Poommitol Chaicherdkiat

THE NORMALIZATION PROCESS

P 157

First Normal Form : 1NF - no repeating groups - PK identified

First Normal Form : 1NF Step 1: Eliminate the Repeating Groups

Step 2: Identify the Primary Key

Step 3: Identify All Dependencies Partial dependencies Transitive dependencies

การกําจัด Repeating Groups

การระบุ PK การระบุ dependencies

First Normal Form : 1NF Step 1: Eliminate the Repeating Groups

การกําจัด Repeating Groups

ทุก Attribute ในแต่ละ cell (record) จะเป็ นค่า Single value นันคือมีได้ ค่าเดียว

EX. จะเห็นได้ ว่าในภาพ

ด้ านขวา จะไม่มี Attribute ตัวใดที มีคณ ุ สมบัติเป็ น Multivalue เลย

P 158

First Normal Form : 1NF Step 2: Identify the Primary Key

การระบุ PK

ทุก Attribute ทีเป็ น PK จะต้ อง มีคณ ุ สมบัติข้อมูลเป็ น not null และ unique EX. จะเห็นได้ ว่าในภาพด้ านขวา

หากกําหนดให้ PROJ_NUM เป็ น PK จะไม่เพียงพอ เนืองจากมีการซํากันของข้ อมูล อาจกําหนดให้ ทงั PROJ_NUM และ EMP_NUM เป็ น PK P 159

First Normal Form : 1NF Step 3: Identify All Dependencies

การระบุ dependencies

Partial dependencies : เป็ น dependencies พืนฐานทีอยู่ใน

ส่วนของ composite primary key* หากเราทราบ PROJ_NUM เราก็จะ ทราบ PROJ_NAME 2) หากเราทราบ EMP_NUM เราก็จะ ทราบ EMP_NAME , JOB_CLASS และ 1)

CHG_HOUR(charge per hour) P 159

First Normal Form : 1NF Step 3: Identify All Dependencies (Cont'd)

Partial dependencies : เป็ น dependencies พืนฐานทีอยู่ใน

ส่วนของ composite primary key* นิยาม Composite primary key คือ การนํา Attribute ตังแต่ 2 ตัวขึนไป มารวมกัน เพือให้ มีคณ ุ สมบัติเป็ น Primary Key http://u51132792066.blogspot.com/2010/11/4-24-2553.html P 159

First Normal Form : 1NF Step 3: Identify All Dependencies (Cont'd)

Transitive dependencies : เป็ น dependencies ระหว่าง nonprime attribute

CHG_HOUR จะขึนอยู่กบ ั JOB_CLASS

ปั ญหา ของ Transitive dependencies คือ มันทําให้ เกิด data anomalies P 159

First Normal Form : 1NF 1NF conversion results

P 162

Second Normal Form : 2NF - 1NF - no partial dependencies

Second Normal Form : 2NF Step 1: Write Each Key Component on a Separate Line Step 2: Assign Corresponding Dependent Attributes

แยกส่ วนประกอบของ key

กําหนดDependent Attributes ทีสอดคล้องกัน

P 161

Second Normal Form : 2NF การแปลงไปยัง 2NF ได้ นนั ก็ต่อเมือ1NF มี composite primary key *แต่หาก 1NF มีลก ั ษณะเป็ น single attribute primary key รู ปแบบตารางนันจะถือเป็ น 2NF ไปเลย

การแปลง 1NF ไปเป็ น 2NF ไม่ยาก เริ มต้ นด้ วยรู ปสุดท้ ายใน 1NF นันคือ...

P 161

Second Normal Form : 2NF Step 1: Write Each Key Component on a Separate Line

แยกส่ วนประกอบของ key

เขียนส่วนประกอบของ key แต่ละตัว แยกบรรทัดกัน จากนัน เขียน original (composite) key ไว้ บรรทัดสุดท้ าย PROJ_NUM EMP_NUM PROJ_NUM

EMP_NUM

แต่ละ component จะกลายมาเป็ น key ในแต่ละตาราง นันคือในขณะนีมี 3 ตาราง (PROJECT, EMPLOYEE, and ASSIGNMENT) P 161

Second Normal Form : 2NF Step 2: Assign Corresponding Dependent Attributes

กําหนดDependent Attributes ทีสอดคล้องกัน

ตารางทัง 3 ตาราง จะถูก อธิบาย โดย relational schemas ดังนี …. - PROJECT (PROJ_NUM , PROJ_NAME) - EMPLOYEE (EMP_NUM , EMP_NAME , JOB_CLASS , CHG_HOUR) - ASSIGNMENT (PROJ_NUM , EMP_NUM , ASSIGN_HOURS) *เนืองจากจํานวนชัวโมงทีเสียไปในแต่ละ project โดยพนักงานแต่ละคน จะขึนอยู่กบ ั PROJ_NUM และ EMP_NUM P 161

Second Normal Form : 2NF 2NF conversion results

P 162

Third Normal Form : 3NF - 2NF - no transitive dependencies

Third Normal Form : 3NF Step 1: Identify Each New Determinant

ระบุแต่ละ Determinant ใหม่

Step 2: Identify the Dependent Attributes

ระบุ Dependent Attribute

Step 3 : Remove the Dependent Attributes from Transitive Dependencies

ลบ Dependent Attributes ออกจาก Transitive Dependencies

P 163

Third Normal Form : 3NF Step 1: Identify Each New Determinant

ใส่ determinant * ของแต่ ละ transitive dependency * โดยเป็ นเหมือน PK ในตารางใหม่

ระบุแต่ละ Determinant ใหม่

* หากคุณมี transitive dependencies ทีแตกต่างกัน 3 ตัว คุณก็จะมี determinants ทีแตกต่างกัน 3 ตัวเช่นกัน

แต่จากตัวอย่างทีศึกษามี transitive dependencies เพียงตารางเดียว ดังนันจึงสามารถเขียน determinant ของtransitive dependencies ได้ ดงั นี

JOB_CLASS

P 163

Third Normal Form : 3NF Step 1: Identify Each New Determinant (Cont'd)

ใส่ determinant * ของแต่ ละ transitive dependency โดย เป็ นเหมือน PK ในตารางใหม่ นิยาม determinant คือ attribute ทีมีคณ ุ สมบัติในการกําหนดค่า attribute ตัวอืนในแถว

A คือ ตัวระบุค่า (Determinant) *ไม่ซํา B คือ Dependent

ทราบค่าของA จะสามารถทราบค่าของ B ได้

http://www.slideshare.net/kunemata/normalization-16222998 P 163

Third Normal Form : 3NF Step 1: Identify Each New Determinant (Cont'd)

ใส่ determinant ของแต่ละ transitive dependency * โดย เป็ นเหมือน PK ในตารางใหม่ นิยาม transitive dependency คือ การไม่ขนตรงกั ึ บคีย์หลัก ถ้ าในความสัมพันธ์ มีคีย์หลักคือ K และattribute A และ B

จะกล่าวว่า attribute B ไม่ขนตรงกั ึ บคีย์หลัก R

เมือ K -----------> A และ A ----------> B และ A ---/--> K

http://u51132792109.blogspot.com/2011/01/normalization-5-54.html P 163

Third Normal Form : 3NF Step 2: Identify the Dependent Attributes

ระบุ Dependent Attribute

ใส่ Attribute ทีเป็ น dependent ของแต่ละ determinant ทีได้ ระบุไว้ ใน step 1

JOB (JOB_CLASS, CHG_HOUR)

ชือของตารางจะต้ องสอดคล้ องกับเนือหาข้ อมูล และฟั งก์ชนั ซึงในตัวอย่างนี ชือ JOB ก็ดจู ะเหมาะสมดี P 163

Third Normal Form : 3NF Step 3 : Remove the Dependent Attributes from Transitive Dependencies

ลบ Dependent Attributes ออกจาก Transitive Dependencies

ลบ dependent attributes ทุกตัวออก จาก transitive

ในตัวอย่างนี คือ จะลบ CHG_HOUR ออกจาก ตาราง EMPLOYEE EMP_NUM → EMP_NAME, JOB_CLASS

P 163

Third Normal Form : 3NF 3NF conversion results

P 164

SUMMARY 1NF conversion results

2NF conversion results

3NF conversion results

Reference

Database Systems - Design, Implementation, and Management (9th Edition) Carlos Coronel, Steven A. Morris, Peter Rob ISBN: 0538469684

THANK YOU

Normal-Form.pdf

Step 1: Eliminate the Repeating Groups การกําจัด Repeating Groups. Step 2: Identify the Primary Key การระบุPK. Step 3: Identify All Dependencies การระบุdependencies. Partial dependencies. Transitive dependencies. Page 4 of 27. Normal-Form.pdf. Normal-Form.pdf. Open. Extract. Open with. Sign In. Main menu. Displaying ...

2MB Sizes 4 Downloads 629 Views

Recommend Documents

No documents