Normal forms. ทฤษฎีของการทำ Normalization เป็นเรื่องเกี่ยวกับการพิจารณาว่า relation ที่กำหนดให้ อยู่ในรูปแบบ Normal form ใด คือ มีความถูกต้องตรงกับกฎเกณฑ์ข้อบังคับ หรือเงื่อนไขบางอย่างที่กำหนดไว้. Universe of Relations (normalized and unnormalized). 1 NF relations (normalized relations).
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation
Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement.Téléchargez la présentation en cliquant sur ce lien.Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.
F I N
Plus de contenu associé
Transcription de la présentation
Normal forms ทฤษฎีของการทำ Normalization เป็นเรื่องเกี่ยวกับการพิจารณาว่า relation ที่กำหนดให้ อยู่ในรูปแบบ Normal form ใด คือ มีความถูกต้องตรงกับกฎเกณฑ์ข้อบังคับ หรือเงื่อนไขบางอย่างที่กำหนดไว้ Universe of Relations (normalized and unnormalized) 1 NF relations (normalized relations) 2 NF relations 3 NF relations BCNF relations 4NF relations PJ/NF (5 NF) relations
Functional dependency (FD) “Functional dependence”หรือ “Functional dependency” Relation R มี attribute x, y attribute y เป็น “Functional dependence”กับ attribute x เขียนเป็นสัญลักษณ์ R.x --> R.y หรือ x y เรียกว่า y functional dependent on x (y ขึ้นกับx อย่างfunction หรือ x functional determines y (x เป็นตัวกำหนด y) ก็ต่อเมื่อ แต่ละค่าของ x ใน R จะมีค่า y ของ R ที่สอดคล้องกับ x เพียงค่าเดียวเท่านั้น (attribute x,y อาจเป็น Composite attribute)
นิยาม A relation R is in first normal form (1 NF) if and only if All underlying domains contain atomic values only Relation ใดๆ อยู่ใน 1 NF ก็ต่อเมื่อ Simple domains ทั้งหมดมีแต่ Atomic Values (ไม่มี repeating group)
S# STATUS CITY P# QTY S1 20 London P1 300 P2 200 P3 400 P4 200 P5 100 P6 100 S2 10 Paris P1 300 P2 400 S3 10 Paris P2 200 S4 20 London P2 200 P4 300 P5 400 Unnormalized
S# STATUS CITY P# QTY S1 20 London P1 300 S1 20 London P2 200 S1 20 London P3 400 S1 20 London P4 200 S1 20 London P5 100 S1 20 London P6 100 S2 10 Paris P1 300 S2 10 Paris P2 400 S3 10 Paris P2 200 S4 20 London P2 200 S4 20 London P4 300 S4 20 London P5 400 Normalized (1 NF)
S# STATUS QTY P# CITY FD diagram in relation FIRST S# P# STATUS CITY QTY
นิยาม Relation ใดๆ อยู่ใน 2 NF ก็ต่อเมื่อ Relation นั้นอยู่ใน 1 NF และทุกๆ Nonkey attribute นั้น Fully FD กับ Primary key จาก FIRST SECOND (S#,STATUS,CITY) SP (S#,P#,QTY) STATUS S# S# QTY CITY P# FD in the relation SECOND and SP
REGISTRATION OWNER MODEL MANUFACTOR NO-CYLINDER YX-01 YJ-77 YW-30 YJ-37 YJ-83 Laser Falcon Corolla Laser Corolla Ford Ford Toyota Ford Toyota 4 6 4 4 4 George Mary George Mary Andrew VEHICLES
OWNER MODEL REGISTRATION-NO MANUFACTOR NO-CYLINDER
OWNER MODEL REGISTRATION-NO MANUFACTOR MODEL NO-CYLINDERS MANUFACTOR
REGISTRATION-NO MODEL MANUFACTOR OWNER NO-CYLINDER MODEL MANUFACTOR YX-01 YJ-77 YW-30 YJ-37 YJ-83 Laser Falcon Corolla Laser Corolla Ford Ford Toyota Ford Toyota Laser Falcon Corolla Ford Ford Toyota 4 6 4 George Mary George Mary Andrew REGISTRATION VEHICLES1
LOAN-APPLICTION-NO APPLICANT APPLICANT-ADDRESS LOAN-TYPE 1 Jill Canberra Home 2 Joe Sydney Mortgage 3 Jill Canberra Personal 4 Max Melbourne Home 1. LOAN APPLICATION 1. Each Loan application has APPLICANT and is identified by unique value of LOAN-APPLICATION –NO 2. Each Loan application-no has one LOAN-TYPE. 3. Each Loan application-no has one APPLICANT-ADDRESS. 4. An applicant can make many applications.
CUSTOMER NAME INVOICE-NO CUSTOMER ADDRESS CUSTOMER SERVICE SERVICE COST SERVICE DATE Joe 6 Sydney Repair 120 June,1992 Joe 6 Sydney Course 320 July,1992 Jill 3 Canberra Repair 80 August,1992 Joe 6 Sydney Repair 150 October1992 2. CUSTOMER –INVOICES Rules for CUSTOMER –INVOICES: 1. Each invoice is to one customer and is identified by a unique value of INVOIC-NO 2. A number of CUSTOMER –INVOICES can be included on one invoice. 3. There is a separate SERVICE-COST for each CUSTOMER – INVOICES on an invoice.
OPERATOR MACHNE DATE QTY-PARTS PRODUCTS TIME-SPENT ON-MACHNE Joe Mach 1 1 June 1992 15 10 Joe Mach 2 1 June 1992 20 12 Bill Mach 1 1 June 1992 12 6 Bill Mach 2 2 June 1992 20 14 4. MACHINE-USE Rules for MACHINE-USE: 1. A machine only bused one operator on a given date. 2. An operator can use any number of machines the one day. T3. TIME-SPEN-ON –MACHHINE is the time spent by an operator on the machine on given DATE, QTY-PARTS-PRODUCES is quantity of parts produced on that machine by the operator on the given date
Boyce/Codd Normal form (BCNF) Relation ใดๆ อยู่ใน BCNF ก็ต่อเมื่อ ทุกๆ Determinant ที่มีอยู่ เป็น Candidate key ด้วย นิยาม S# STATUS CITY SNAME Relation S(S#,SNAME,STATUS,CITY) Candidate key มี S#, SNAME Determinant มี S#, SNAME STATUS, CITY นั้น Mutually independent กัน คือ FD S.CITY ----- S.STATUS
Example 2 S# SNAME P# QTY Smith Smith Smith Smith P1 P2 P3 P4 300 200 400 200 S1 S1 S1 S1 relation SSP (S#,SNAME,P#,QTY) S# P# QTY SNAME
Example 3 S J T Smith Smith Jones Jones Math Physics Math Physics Prof.White Prof.Green Prof.White Prof.Brown relation SJT (S,J,T) S = Student, J = Subject, T = Teacher วิชาใดๆ แต่ละ Student จะถูกสอนโดย Teacher เพียงคนเดียว (S,J) ---- T แต่ละ Teacher นั้นจะสอนได้เพียง Subject เดียว (แต่ Subject หนึ่ง อาจสอนโดยหลายๆ Teacher ได้) T --- J
S T J Candidate key มี (S,J), (S,T) Determinant มี (S,J), (S,T), T แก้ปัญหาโดย ST(S,T) และ TJ(T,J) ST มี Candidate key คือ (S,T) ไม่มี determinant TJ มี Candidate key คือ T determinant คือ T
Example 4 relation EXAM(S,J,P) S = Student, J = Subject, P = Position ความหมายของ Exam tuple (S,J,P) คือ Student S สอบ Subject J และได้ Position P ใน class ข้อบังคับ - ไม่มีโอกาสที่ 2 student จะได้ Position เดียวกัน ใน Subject เดียวกัน S J P S J P Candidate key มี (S,J), (J,P) Determinant มี (S,J), (J,P)
นิยาม ของ MVD (Multi Value dependency) Relation R ใดๆ ที่มี Attribute A, B, C (อาจเป็น Composite attribute) แล้วมี MVD R.A -> R.B เกิดขึ้น ก็ต่อเมื่อ Set ของค่า B จะขึ้นกับค่า A เท่านั้น และเป็นอิสระกับค่า C (R.A - R.B อ่านว่า R.B “Multi dependent” กับ R.Aหรือ R.A “Multi determine” กับ R.B ทุกๆครั้งที่ relation R ใดๆ R(A,B,C) มี MVD R.A --> R.B สรุปได้ว่า มี MVD R.A ---> R.C ด้วย เพราะ B, C เป็นอิสระต่อกัน เขียนแทนด้วย R.A ---> R.B / R.C MVD เป็น general case (กรณีทั่วไป) ของ FD FD เป็น special case (กรณีทั่วไป) ของ MVD
นิยามของ 4 NF Relation R อยู่ใน 4 NF ก็ต่อเมื่อ เมื่อไรก็ตามที่มี MVD ใน R เช่น A ---> B แล้ว ทุกๆ attribute ของ R มี FD กับ A ด้วย นั่นคือ ถ้ามี MVD A ---> B แล้ว MVD นั้นเป็น FD A -- B ด้วย หรือ ถ้า R อยู่ใน 4 NF แล้ว R นั้นอยู่ใน BCNF และทุกๆ MVD ใน R จริงๆ เป็น FD
CUSTOMER – Customer number (unique) - Ship to address (several per customer) - Balance - Credit Limit - Discount ORDER - Order number (unique) - Customer number - Ship to address - Date of order - Detail lines (several per customer) - item number - quantity ordered - quantity out ITEM - Item number (unique) - Manufacturing plants - Quantity on hand at each plant - Stock danger level for each plant - Item description
BAL ADDRESS CUST CREDLIM DISCOUNT QTYORD ORD# DATE LINE# QTYOUT ITEM# DESCN QTYOH PLANT# DANGER FD diagram
Department Employee Project Office Phone Job Salary History
The Company ประกอบด้วยหลายๆแผนก (department) • แต่ละแผนก (department) ประกอบด้วยกลุ่มพนักงาน (employee) • กลุ่มของ Project และกลุ่มของ office • แต่ละ employee มีประวัติการทำงานที่ผ่านมา (job history) และแต่ละ job • มีเงินเดือน(salary) ที่เคยได้รับมา • - แต่ละ office ประกอบด้วยกลุ่มของโทรศัพท์ (phone) Department ประกอบด้วย department number(unique), งบประมาณ (budget) และ manager (unique) Employee ประกอบด้วย employee number (unique), current project number, office number, phone number, แต่ละ job ในอดีตที่เคยทำ (plus date and salary) Project ประกอบด้วย project number (unique), budget Office ประกอบด้วย office number (unique), area in square feet และ number (unique) of all phones in that office
DBUDGET AREA DEP# MGR# OFF# PHONE# PROJ# PBUDGET EMP# DATE SALARY JOBTITLE FD diagram