Baocao Chuanhoa

  • View
    9

  • Download
    0

Embed Size (px)

DESCRIPTION

 

Transcript

  • 1. L THUYTCHUN HONhm 4 Trn Tn TL Quang ChinTrng Khc TngQuch Xun HngV Hoi Trung

2. Chun ho l g ? Cho lc quan h R = , 1 phn tch cn c xem l c ngha nu n gim c d tha d liu. L thuyt chun ho s xc nh cc dng chun ca 1 lc quan h. Qu trnh phn tch 1 lc thnh cc lc con sao cho cc lc con u thuc 1 dng chun no c gi l qu trnh chun ho. 3. Cc dng chun lc quan h Dng chun 1NF Dng chun 2NF Ph thuc a tr Dng chun 3NF Dng chun BCNF Dng chun 4NF Ph thuc kt ni Dng chun 5NF 4. Dng chun 1NF nh ngha: Mt lc R c gi l thuc dng chun 1NF (k hiu: R 1NF) nu min gi tr ca cc thuc tnh trong R ch cha nhng gi tr nguyn t (khng th phn chia c na) Quy c: Tt c cc lc quan h c xt u thuc 1NF. 5. Dng chun 2NF Cc khi nim - nh ngha 1 (thuc tnh kho) : Cho R= . Khi , thuc tnh A c gi l thuc tnh kho nu A thuc kho K no ca R.- V d R = , vi U = ABCD F = {AB C, C D} K = {AB} R c 2 thuc tnh kho: A v B v R c thuc tnh khng kho : C v D 6. Dng chun 2NF (tip)- nh ngha 2 (Ph thuc hm y ) :Cho R = . Khi , X Y F c gi l 1 ph thuc hm y nu : Z $ sao cho ZY F+X Nhn xt: Nu X U F+ l 1 ph thuc hm y khi X l kho ca R. V d :NKBH = vi U = {NG, SP, MH, G, SL}F = {SP, MHU, MHG} {SP, MH} G F+ khng l ph thuc hm y (v $ MH {MH, SP}: MH G F+) 7. Dng chun 2NF (tip) - nh ngha 2NF :Cho R = . Khi , R c gi l thuc 2NF (k hiu: R 2NF) nu vi mi thuc tnh khng kho A l ph thuc hm y vo mi kho ca R.(A - khng kho, X K: X A F+ l ph thuc hm y ) V d: Xt lc quan h nu trn NKBH c 2 thuc tnh kho: SP v MH. Suy ra cc thuc tnh khng kho: NG, G, SL. Theo trn ta c : {SP, MH} G F+ khng l ph thuc hm y . NKBH 2NF 8. Dng chun 2NF (tip)- Nhn xt: + Nu mi kho ca lc quan h R ch c 1 thuc tnh th R thuc 2NF.+ Ta c th chng minh rng :R 2NF XA F+, vi X K ( K l kho ca Rth:.hoc A l thuc tnh kho. .hoc A X (XA l ph thuc hm tm thng) 9. Dng chun 3NF - nh ngha: (R 3NF) Cho R = . Khi R c gi l thuc 3NF (k hiu: R 3NF) nu XA F+ vi A X th:+ Hoc X l siu kho + Hoc A l thuc tnh kho - V d:NKBH = , vi U = {STT, NGAY, MH, TH, G, SL}, F = {STTU, MHTH, MHG} NKBH 2NF (do lc c 1 kho duy nht l STT ch c 1 thuc tnh) nhng NKBH 3NF v : 10. Dng chun 3NF (tip)NKBH c: K = {STT}Ta c MH TH F+ nhng: + MH khng l siu kho + TH khng l thuc tnh kho- Phn tch NKBH thnh 2 lc con:+HANG = , vi U1 = {MH, TH, G} vF1 = {MH U1}+NK = , vi U2 = {STT, NGAY, MH, SL} v F2 = {STT U2}r rng HANG v NK thuc dng chun 3NF 11. Dng chun 3NF (tip) - Nhn xt : + Nu R 3NF th R 2NF. + Ta c th chng minh rng: . R 3NF $ ph thuc bc cu: X Y F+ v Y A F+ vi: + X l kho (X_kho)+ Y khng l siu kho+ A l thuc tnh khng kho v A XY Hay: . R 3NF $ X_kho Y, m Y A_khng kho 12. Thut ton 1: Phn tch thnh cc lc con 3NF bo ton thng tinVo: R = Ra: = (R1, R2, , Rk) vi Ri 3NF (i = 1,k) v l bo ton thng tin. Phng php: Bc 1: Kim tra R 3NF? ( $ XY A?)Nu R 3NF: khng phn tch v dngNu R 3NF: ($ XY A) phn tch R thnh 2lc con: = (YA, UA) Bc 2: Kim tra ln lt cc lt cc lc con cthuc 3NF khng, nu khng thuc th li phntch tip cho n khi no tt c cc lc conu thuc dng chun 3NF. By gi chng ta sc 1 cy phn tch (cy nh phn) m cc nt l lcc lc con thuc 3NF. 13. Thut ton 1: Phn tch thnh cc lc con 3NFbo ton thng tin (Tip) procedurePhantach(U, F); begin if ($ XY A (ph thuc bc cu)) thenbeginPhantach(YA,F1);Phantach(UA,F2);end; end;Lu : Nu phn tch = (U1, , Un) tn ti Ui l tp con ca Uj (i j) th ta loi b lc tng ng vi tp thuc tnh Ui. 14. Thut ton 1: Phn tch thnh cc lc con 3NFbo ton thng tin (Tip) v d trn $ {STT} {MH, TH} G = ({MH, TH, G}, {STT, NGAY, MH, TH, SL}) 3NF 3NF {MH,TH} {STT,NGAY,MH,SL} 3NF 3NF = ({MH,TH, G},{STT,NGAY,MH,SL}) Lu : Thut ton trn khng duy nht 15. Thut ton 2: Phn tch 3NF bo ton thng tin v bo ton ph thuc hmVo :R = Ra: = (R0, R1, R2, , Rk) vi Ri 3NF (i = 0,k) l bo ton thng tin v bo ton ph thuc hm. Phng php: Bc 1: Xc nh ph ti thiu ca F: F = {Xi Ai | i = 1,m } Bc 2: Tm 1 kho X bt k ca R. Bc 3: Xc nh lc con R0 = vi U0 = X Bc 4: Ln lt xc nh cc lt con Ri = vi Ui = XiAi (i = 1,m ) Bc 5: Nu $i j m Ui Uj (i, j = 0, m ) th loi b Ri. Qu trnh ny s tip tc cho n khi khng th loi b c mt Ri no na. 16. Thut ton 2:Phn tch 3NF bo ton thng tin v bo ton ph thuc hm (tip)V d: Cho R = vi U = ABCD, F = {AB, BC, CDA, ACD} Bc 1: Ta c 1 ph ti thiu ca F l:F = {AB, BC, CDA, AD} Bc 2: Ta c A l 1 kho ca R. Bc 3: R0 = vi U0 = A , F0 = Bc 4:R1 = R2 = R3 = < ACD, {CDA, AD, AC}>R4 = Bc 5: Loi R0 v R4 Kt lun: = (AB, BC, ACD) 17. Dng chun BCNF nh ngha: (R BCNF)Cho R = . Khi : R BCNF XA F+ vi A X th: X l siu kho.V d: Cho R = , vi U = CSZ v F = {CSZ, ZC} Xt r R:r = CSZVN Hue 84VN HN84MA 1MB 1MC 2MD 2 XA99=> D tha d liu 18. Dng chun BCNF (tip)C ZS Z = r VN 84Hue 84 M1HN84 M2 A 1X 99 B 1Khng d tha C 2 D 2 A99 Khng d thaR rng R 3NF (v R c 2 kho: CS v SZ), nhng R vn d tha. 19. Dng chun BCNF (tip) v d trn R BCNF v $ ZC F+ vi Z khng l siu kho.Nhng: R1 = vi U1 = CZ v F1 = {Z C} R2 = vi U2 = SZ v F2 = Ta c R1, R2 BCNF.Nhn xt:R BCNF R 3NFTa c thut ton phn tch 1 lc quan h thnh cc lc con thuc BCNF v phn tch ny bo ton thng tin nh sau: 20. Thut ton phn tch 1 lc quan h thnh cc lc con thuc BCNF bo ton thng tinVo: R = Ra: = (R1, R2, , Rk) vi Ri BCNF (i = 1, k) l bo ton thng tin Phng php: Da vo gii thut sau:procedurePT(U,F) begin if ( $XA F+ vi AX v X khng l siu kho) then beginPT(XA,F1);PT(UA,F2); end; end; 21. Ngi ta chng minh: khng tn tai 1 gii thut phn tch 1 lc quan h thnh cc lc con thuc BCNF va bo ton thng tin va bo ton ph thuc hm 22. XIN CHN THNH CM N !