You are on page 1of 53

THIT K

C S D LIU QUAN H
2
Ni dung
3.1 Nguyn tc thit k cc lc quan h.
3.2 Ph thuc hm.
3.3 Cc dng chun.
3.4 Mt s thut ton chun ha.
3
3.1 Nguyn tc thit k cc lc quan h
Khi thit k mt CSDL quan h: cn chn lc
CSDL ph hp.
Trng tm ca thit k cc lc CSDL: ph
thuc d liu (Data Dependency) tc l cc mc
rng buc c th gia cc gi tr hin hu ca cc
lc .
Cc vn cn quan tm khi thit k CSDL:
D tha d liu (Redundancy)
Khng nht qun (Inconsistency)
D thng khi thm b (Insertion anomalies)
D thng khi xo b (Deletion anomalies)
4
V d 3.1: Xt lc quan h
BANHANG(Ngy, M hng, Tn hng, n gi, S lng).
Ngy M hng Tn hng n gi S lng
01/06/2010 M1 Radio 1000 1
01/06/2010 M3 TV 4000 2
01/06/2010 M6 Xe p 1000 1
02/06/2010 M2 My git 3000 2
02/06/2010 M1 Radio 1000 3
03/06/2010 M4 Video 5000 2
01/06/2010 M9 My nh 2000 1
5
Nhn xt
a) Tn hng c lp li khi mi mt hng cng M hng
c cung cp (D tha d liu)
b) Khi cp nht, gi s c s thay i tn hng tng ng vi
mt M hng ta thay M hng khng c tn duy nht
(Khng nht qun)
c) Khi c mt mt hng mi, nhng cha bit n gi, s
lng. C th t cc gi tr rng (NULL) nhng thnh
phn ny, nhng khi c s liu, c th nhng gi tr rng
ny khng c loi b (D thng khi thm b)
d) Khi xa n gi cng mt mt hng c th lm sai lch
doanh thu, v n gi ca cng mt mt hng gia cc
ngy c th khc nhau (D thng khi xa)
gii quyt iu cn xc nh s lin quan cc thuc
tnh, phn r thnh nhng quan h nh hn.
Khi nim ph thuc hm c a ra nhm xc nh mi
quan h gia cc thuc tnh.
6
3.2 Ph thuc hm
nh ngha 3.1: Xt lc quan h gm n thuc tnh
R(U), U={A
1
, A
2
,, A
n
}
PTH gia hai tp thuc tnh X, Y _ U
K hiu: X Y (c: X xc nh hm Y hay Y ph thuc hm X)
r(R), t
1
, t
2
e r nu t
1
[X] = t
2
[X] th t
1
[Y] = t
2
[Y].
X l v tri v Y l v phi ca PTH.
V d 3.2
r(R) A B
1 4
1 5
3 7
r khng tha A B, nhng tha B A
NHANVIEN_PHONGBAN
TenNV MaNV NgSinh Diachi MaPB TenPB TrPhong
MaNV MaPB MaPB {TenPB, TrPhong} MaNV TenNV
7
Bao ng ca tp PTH
nh ngha 3.2: Trn lc quan h R; F l tp cc
PTH, cho XY l mt PTH.
- Ta ni rng tp PTH F suy din logic X Y k hiu
F X Y,
nu bt k quan h r ca R tha cc ph thuc trong F th
cng tha X Y.

nh ngha 3.3: Bao ng ca tp PTH (Closure of FD) F
l tp cc ph thuc hm c suy din logic t F, k
hiu l F
+,
ngha l:
F
+
= { X Y | F X Y}
8
Bao ng ca tp PTH
F l tp PTH trn R
F = (MaNV TenNV, MaPB {TenPB,
TrPhong}, MaNV MaPB).
reR tha F v MaNV {TenPB, TrPhong}
cng ng vi r th MaNV {TenPB, TrPhong}
gi l c suy din t F.
Bao ng ca F, k hiu F
+
, gm
F v tt c cc PTH c suy din t F.
F gi l y nu F = F
+
.
9
Lut suy din
xc nh c F
+
, hay nhn bit X Ye F
+
?
Lut suy din dng suy din mt PTH mi t mt tp
PTH cho trc.
H tin Armstrong (Armstrongs axioms- 1974)
Phn x (Reflexivity): Y _ X X Y.
Tng trng (Augmentation): X Y XZ YZ, vi XZ=XZ.
Bc cu (Transitivity): X Y, Y Z X Z.
Cc h qu:
Phn r (Decomposition rule): X YZ X Y, X Z.
Hp (Union rule): X Y, X Z X YZ.
Ta bc cu (Pseudo transitivity rule): XY, WYZ WX Z.
10
V d 3.3 : Cho R = ABC v tp ph thuc hm

Chng minh rng: F
Tht vy t :
C A (gi thit)
BC AB (lut tng trng (1) thm B)
AB C (gi thit)
AB ABC (lut tng trng (3) thm AB)
BC ABC (lut bc cu t (2) v (4))
Lut suy din
{ } A C C AB F = ,
ABC BC
11
Tnh ng n v y ca h tin Armstrong
B 3.1: H tin Armstrong l ng n (Soundness)
B 3.2: H tin Armstrong l y (Completeness)
ngha:
- H tin Armstrong l ng n, ngha l X Y c suy
din t h tin Armstrong th X Y ng trong mi quan
h m mi ph thuc hm ca F ng.
- Tnh y ca h tin Armstrong c ngha l: vi F l tp
ph thuc hm cho trc. Gi F
+
h bao ng ca F, F
0
l tp
cc ph thuc hm c th suy dn t h h tin Armstrong
th F
+
= F
0
.
B 3.3: X Y c suy ra t tp ph thuc hm F cho
bng cch s dng h tin Armstrong Y_ X
+
.

12
Chng minh B 3.1 (Tnh ng n)
Chng minh: Cn chng minh 3 tin ng :
a1) Y_X _ R th X Y
r(R) tha F: t, t e r : t(X) = t(X) t(Y) = t(Y) do Y _ X
a2) X Y, Z_ R XZ YZ
r(R) tha F : t, ter theo gi thit ta c :
t(X) = t(X) t(Y) = t(Y) (1)
Nu t(XZ) = t(XZ) t(X).t(Z) = t(X).t(Z)
t(Y).t(Z) = t(Y).t(Z) t(Y) = t(Y) (2)
T (1), (2) mu thun, vy: t(XZ) = t(XZ) t(YZ) = t(YZ)
a3) X Y, Y Z th X Z
r(R) tha F: t, t e r :
t(X) = t(X) t(Y) = t(Y) do XY
t(Y) = t(Y) t(Z) = t(Z) do Y Z
Vy t(X) = t(X) t(Z) = t(Z) pcm.
13
Chng minh B 3.2 (Tnh y )
Do tnh ng n ca h tin Armstrong nn: F
0
_ F
+
, cn phi chng minh:
F
+
_ F
0
(XY e F
+
X Y e F
0
)
(X Y e F
0
X Y e F
+
) (Phn chng)
Chng minh:
Gi s X Y e F
0
(ngha l PTH X Y khng th suy dn bi h tin
Armstrong t F).
Xt quan h r gm hai b nh sau :
11 ... 1 11 ... 1
11 ... 1 00 ... 0
Cc thuc tnh Cc thuc tnh
thuc X
+
cn li
Ta thy tt c cc ph thuc hm trn F u tha r, gi s ngc li :
-VW e F nhng khng tha r V_X
+
, W . X
+
-A _ W, A X
+
= C.
Do V_X
+
, theo b 3.3: XV eF
o
v VW, WA, theo lut bt cu XA
(Mu thun)
Nu X Y eF
+
X Y tha r (theo nh ngha F
+
) Y _ X
+
(1)
M gi thit: X Y e F
0
Y. X
+
(2)
(1) v (2) mu thun, vy X Y e F
+
(pcm).
Ni khc hn: F
+
= F
0
.
14
Bao ng ca tp thuc tnh
Nhn xt:
Vic xc nh F
+
ca tp PTH F l kh khn v F
+
rt ln, d F
c th rt b.
Chng hn: Xt : F = {A B
1
, A B
2
, , A B
n
}
Th F
+
= {A Y| Yc {B
1
B
2
B
n
} |F
+
| = 2
n
.
Trong nhiu trng hp, ta khng cn tm ton b F
+
, m ch
cn xt xem mt ph thuc hm cho trc c thuc F
+
khng ?
xt xem X Ye F
+
, theo b 3.3, ta cn tm X
+
:
nu Y _ X
+
th X Y e F
+

Bao ng ca tp thuc tnh :
X l tp thuc tnh
Bao ng ca X i vi F, k hiu X
F
+

X
F
+
= {A e U | X A e F
+
}
Nhn xt: X Y e F
+
Y _ X
+
.
15
Thut ton tm X
+
Thut ton 3.1
Nhp: U, F v X _ U
Xut: X
+

Phng php: Ln lt tnh cc tp X
(0)
, X
(1)
, ..., X
(i
),. .
B1: X
(0)
= X;
B2: X
(i+1)
= X
(i)
A, nu - YZe F, AeZ v Y_ X
(i)
,
Ngc li qua B3.
B3: xut X
+


= X
(i)
.
16
V d tm X
F
+
Cho:
F = {AB C, BC D, D EG}.
X = BD.
Tnh X
F
+
:
X
(0)
= BD.
Lp 1:
Tm cc PTH c v tri l tp con ca X
(0)
= BD
C D EG, thm EG vo X
(0)
ta c X
(1)
= BDEG.
Lp 2:
Tm cc PTH c v tri l tp con ca X
(1)
= BDEG
Khng c PTH no. X
(2)
= X
(1)

Vy X
F
+
= X
(2)
= {BDEG}.
17
Chng minh tnh ng n thut ton 3.1
Ta phi chng minh: A, A _X
+
-j: A _X
(j)
:: Chng minh bng qui np:
Xt j=0, A _X
(0)
: XAe F
+
A _X
+

Gi s ng n bc j-1, xt bc th j:
A _X
(j)


-Y_X
(j-1):
YAe F
+
(1)
Do Y_X
(j-1)
XYe F
+
(2)
T (1) v (2) XAe F
+
Ae X
+
18
Chng minh tnh ng n thut ton 3.1(tt)

: A, A _X
+


-j: A _X
(j)


Gi i l gi tr X
(i)
=X
(i+k)
k=0,1,2, ...
Xt quan h r gm hai b nh sau:
11 ... 1 11 ... 1
11 ... 1 00 ... 0
Cc thuc tnh Cc thuc tnh
thuc X
i
+
khng thuc X
i
+

Tng t: Theo chng minh 3.2, mi PTH trn F u tha r.
Tht vy. nu UVeF nhng khng tha r U_X
(i)
v V.X
(i)

X
(i+1)
=X
(i)
(Mu thun)
Do A _X
+
X A e F
+
(B 3)
V do h tin Armstrong l ng v y X A e F
+

X A tha r

A _X
(i)
C pcm.
19
Kim tra PTH suy din
Cho F = {AB C, A D, D E, AC B}
Hai PTH AB E v D C c c suy din t F hay
khng?
X X
F
+

AB ABCDE
D DE
c suy din t F
Khng c suy din t F
20
Ph ca cc PTH (Covers for functional Dependencies)
nh ngha 3.4: Hai tp ph thuc hm F v G trn lc
R l tng ng, k hiu F G, nu F
+
= G
+.
Nu F G
th F gi l ph G.
F suy din G, k hiu F G nu XYeG th F XY
nh l 3.1: Cho hai tp ph thuc hm F v G trn lc
R, FG khi v ch khi F G v G F.
Chng minh: Trc ht ta d thy: F
+
= (F
+
)
+
Mt khc: F G ( F G v G F )
F G G_ F
+
G
+
_ (F
+
)
+
= F
+
(1)
G F F _G
+
F
+
_ (G
+
)
+
= G
+
(2)
(1), (2) (G
+
_ F
+
) . (F
+
_ G
+
) F
+
= G
+

pcm.
21
Thut ton 3.2: Kim tra tnh tng ng gia F v G
Vo : F = {L
i
R
i
/ i = 1..n}; G = {L
j
R
j
/ j = 1..n}
Ra : F
+
= G
+
?
Phng php :
i = 1..n, ln lt kim tra L
i
R
i
e G
+
? (tnh (L
i
)
+
i vi
tp ph thuc hm G, nu R
i
_ (L
i
)
+
th L
i
R
i
e G
+

Nu mi ph thuc hm trong F u thuc G th F
+
_ G
+

Tng t nu mi ph thuc hm trong G u thuc F
+
th
G
+
_ F
+

Nu c hai iu trn u ng th F
+
= G
+

Cc tp PTH tng ng
22
Tp PTH ti thiu
Tp PTH F l ti thiu nu tha cc iu kin sau
Mi PTH ca F ch c mt thuc tnh v phi.
Khng th thay X A thuc F bng Y A vi Y c X
m tp mi tng ng vi F.
Nu b i mt PTH bt k trong F th tp PTH cn li
khng tng ng vi F.
Ph ti thiu (Minimal Covers) ca tp PTH E l
tp PTH ti thiu F tng ng vi E.
Nhn xt
Mi tp PTH c t nht mt ph ti thiu.
23
Thut ton tm ph ti thiu (Bernstein, 1976)
Thut ton 3.3:
Nhp: tp PTH E.
Xut: ph ti thiu F ca E.
Phng php :
B1: F := C.
B2: (Tch cc PTH c v phi l 1 thuc tnh)
Vi mi X Y e E, Y = {A
1
, , A
k
}, A
i
e U
F := F {X {A
i
}}.
B3: (Loi b cc thuc tnh d tha v tri)
Vi mi X {A} e F, X = {B
1
, , B
l
}, B
i
e U
Vi mi B
i
, nu A e (X - {B
i
})
F
+
th


F := (F - {X {A}}) {(X - {B}) {A}}.
B4: (Loi b cc PTH d tha)
Vi mi X {A} e F
G := F - {X {A}}
Nu A e X
G
+
th F := F - {X {A}}.
24
V d tm ph ti thiu
Tm ph ti thiu ca E = {A BC, A B, B C,
AB C}
B1: F = C.
B2: F = {A B, A C, B C, AB C}.
B3: Xt AB C
(B)
F
+
= C
F = {A B, A C, B C}.
B4: A C tha.
F = {A B, B C}.
25
Siu kha v kha
Cho R(U)
S _ U l siu kha nu
r e R, t
1
, t
2
e r, t
1
= t
2
th t
1
[S] = t
2
[S].
K _ U l kha nu K l siu kha nh nht. A e K
c gi l thuc tnh kha.
Nhn xt
S xc nh hm tt c cc thuc tnh ca R: (S)
+
=R
R c th c nhiu kha.
26
Xc nh kha ca lc
Thut ton 3.4: Tm mt kha ti thiu ca quan h
Nhp: tp PTH F xc nh trn lc R(U)
U = {A
1
, , A
n
};
Xut: kha K ca R.
Phng php :
Bc 0 : t K
0
= U
Bc i : Tnh
K
i 1
\ {A
i
} nu K
i-1
\ {A
i
} U
K
i
=
K
i-1
nu ngc li
t K = K
n
27
V d 3.4: Tm kha ca lc
Cho R(U), U = {A, B, C, D, E, F, G}.
F = {B A, D C, D BE, DF G}.
Tm kha ca R
B1:
K = ABCDEFG.
B2:
Lp 1: (BCDEFG)
F
+
= BCDEFGA K = BCDEFG.
Lp 2: (CDEFG)
F
+
= CDEFGBA K = CDEFG.
Lp 3: (DEFG)
F
+
= DEFGCBA K = DEFG.
Lp 4: (EFG)
F
+
= EFG.
Lp 5: (DFG)
F
+
= DFGCBEA K = DFG.
Lp 6: (DG)
F
+
= DGCBEA.
Lp 7: (DF)
F
+
= DFCBEAG K = DF.
B3:
Kha l K = DF.
28
Xc nh tt c kha ca lc
Nhp: tp PTH F xc nh trn lc R(U).
Xut: tt c kha ca R.
Thut ton 3.5
B1:
Xy dng 2
n
tp con ca U = {A
1
, , A
n
};
S = { };
B2:
Vi mi tp con X _ U
Nu U _ X
F
+
th S = S {X}.
B3:
X, Y e S, nu X c Y th S = S - {Y}.
B4:
S l tp cc kha ca R.
29
V d tm tt c kha ca lc
Cho R(U), U = {A, B, C, D, E, F}.
F = {AE C, CF A, BD F, AF E}.
Tm tt c kha ca R
Tp siu kha
S = {ABD, BCD, ABCD, ABDE, BCDE, ABCDE, ABDF, BCDF, ABCDF,
ABDEF, BCDEF, ABCDEF}.
ABD
BCD
ABCD
ABDE
BCDE
ABCDE
ABDF
BCDF
ABCDF
ABDEF
BCDEF
ABCDEF
30
3.3 Chun ha lc CSDL
Cc dng chun
Dng 1 (1 Normal Form - 1NF).
Dng 2 (2 Normal Form - 2NF).
Dng 3 (3 Normal Form - 3NF).
Dng Boyce - Codd (Boyce - Codd Normal
Form - BCNF).
31
Khi nim
Kha ng vin (candidate key): Nu mt lc quan h c
nhiu hn mt kha th cc kha c gi l cc kha
ng vin.
Kha chnh (primary key): Mt trong nhng kha ng vin s
c ch nh lm kha chnh v cc kha cn li gi l cc
kha ph (secondary key).
Mt lc quan h phi c mt kha chnh.
Mt thuc tnh ca mt lc quan h R c gi l thuc
tnh kha ca R nu n l mt thnh phn ca kha chnh
ca R.
Mt thuc tnh c gi l thuc tnh khng kha nu n
khng phi l thuc tnh kha.
32
Dng chun 1
nh ngha 3.5: Lc quan h R c gi thuc dng chun
1 nu v ch nu mi thuc tnh ca R l thuc tnh n.
Go Vap 987654321 4 Hanh chinh
Tan Binh,
Thu Duc
333445555 5 Nghien cuu
CacTruso TrPhg MaPB TenPB
PHONGBAN
PHONGBAN
TenPB MaPB TrPhg Truso
Nghien cuu 5 333445555 Tan Binh
Nghien cuu 5 333445555 Thu Duc
Hanh chinh 4 987654321 Go Vap
Khng thuc
dng chun 1
Thuc dng chun 1
Nhn xt: Dng chun 1 c th dn n s trng lp d
liu. Do gy ra cc d thng v cp nht d liu

33
Dng chun 2 theo kha chnh (1)
nh ngha 3.6: Lc quan h R c gi l thuc dng chun 2 nu
mi thuc tnh khng kha ca R ph thuc y vo kha chnh
ca R.
R(U), K _ U l kha chnh ca R
A e U l thuc tnh khng kha nu A e K.
X Y l PTH y nu A e X th (X - {A}) Y khng ng trn R.
Ngc li X Y l PTH b phn.
V d
FD2
FD1
Diadiem TenDA TenNV SoGio MaDA MaNV
FD3
NVIEN_DUAN
Thuc tnh khng kha
PTH y
PTH b phn
34
Dng chun 2 theo kha chnh (2)
FD2
FD1
Diadiem TenDA TenNV SoGio MaDA MaNV
FD3
NVIEN_DUAN
NV_DA1
MaNV MaDA SoGio
FD1
NV_DA2
MaNV TenNV
FD2
NV_DA3
MaDA TenDA Diadiem
FD3
3 lc NV_DA1, NV_DA2, NV_DA3 thuc dng chun 2
35
Dng chun 2 theo kha chnh (3)
Nhn xt
Mi lc quan h thuc dng chun 2 cng thuc
dng chun 1.
Cn xut hin s trng lp d liu. Do gy ra cc d
thng v cp nht d liu.
NHANVIEN_PHONGBAN
TenNV MaNV NgSinh DChi MaPB TenPB TrPhong
FD1
FD2
Thuc dng
chun 2
36
Dng chun 3 theo kha chnh (1)
nh ngha 3.7: Lc quan h R c gi l thuc dng chun 3 nu
R thuc dng chun 2.
Mi thuc tnh khng kha ca R khng ph thuc bc cu vo kha
chnh ca R.
Cho R(U)
X Y l PTH bt cu nu -Z _ U, Z khng l kha v cng khng l tp
con ca kha ca R m X Z v Z Y ng trn R.
V d

FD2
FD3
FD1
TenPB MaPB TrPhong DChi NgSinh MaNV TenNV
NHANVIEN_PHONGBAN
PTH bc cu
37
Dng chun 3 theo kha chnh (2)
Nhn xt
Mi lc quan h thuc dng chun 3 cng thuc
dng chun 2.
PTH bc cu l nguyn nhn dn n trng lp d
liu.
Dng chun 3 l dng chun ti thiu trong thit k
CSDL.
NV_PB1
TenNV MaNV NgSinh Diachi MaPB
NV_PB2
MaPB TenPB TrPhg
Thuc dng
chun 3
38
Dng chun 2 tng qut
nh ngha 3.8: Lc quan h R c gi l thuc dng
chun 2 nu mi thuc tnh khng kha ca R ph thuc
y vo cc kha ca R.
Cho R(ABCDEF) c 2 kha l A v BC.
FD3
FD2
FD1
F E D C B A
FD4
R
FD5
Lc R khng thuc dng chun 2
39
Dng chun 3 tng qut
nh ngha 3.9: Lc quan h R c gi l thuc dng
chun 3 nu PTH X A ng trn R th
X l siu kha ca R, hoc
A l thuc tnh kha ca R.
R1(ABCDE) c 2 kha l A v BC.





FD2
FD1
E D C B A
FD4
R1
Lc bn
thuc dng
chun 2,
nhng khng
thuc dng
chun 3
FD5
40
3.4 Phn r lc quan h
Lc quan h R(A
1
, , A
n
)
Tp hp tt c cc thuc tnh ca cc thc th.
Xc nh tp PTH F trn R.
Phn r
S dng cc thut ton chun ha tch R thnh tp
cc lc D = {R
1
, , R
m
}.
Yu cu
Bo ton thuc tnh.
Cc lc R
i
phi dng chun 3 hoc Boyce-
Codd.
41
Phn r bo ton PTH
Tnh cht bo ton PTH
Xt lc R v tp PTH F. Gi s R c phn r
thnh D = {R
1
, , R
m
}.
t t
Ri
(F) = {X Y e F
+
: X Y c R
i
}.
D c gi l phn r bo ton ph thuc hm i vi F nu
(t
R1
(F) t
Rm
(F))
+
= F
+
.
V d
FD2
FD5
FD1
D C B A
R11
R111
A C D
FD1
R112
B D
FD5
42
Phn r bo ton PTH (tt)
R11 A B C D
1 o | 2
2 | 3
3 o o 2
2 o 3
4 | 4
3 2
2 | 1
D C A R111
| 3
4
2
D
o
o
B R112

4 | o 4
2 | o 1
D C B A
Thm b (4, |, 4) vo R111
v (4, o) vo R112
th trng thi csdl s khng
tha PTH FD2
43
Thut ton phn r lc DC3 v bo ton
PTH (Berstein 1976)
Thut ton 3.6
Nhp: R(U), U = {A
1
, , A
n
} v tp PTH F.
Xut: D = {R
1
, , R
m
}, R
i
dng chun 3.
B1: Tm ph ti thiu G ca F.
B2: Vi mi X A
j
e G, xy dng lc R
i
(U
i
),
U
i
= X {A
j
}. Kha chnh ca R
i
l X.
B3: Gi s xong B2 ta c cc lc R
1
, , R
m
.
Nu U
1
U
m
= U th xy dng thm lc
R
m+1
(U
m+1
), U
m+1
= U - (U
1
U
m
).
Kha chnh ca R
m+1
l U
m+1
.
B4: Xut cc lc R
i
.
44
V d phn r bo ton PTH (1)
Cho
R(ABCDEFG)
F = {B A, D C, D EB, DF G}
Tch v dng chun 3, bo ton PTH
B1:
Ph ti thiu G = {B A, D C, D B, D E, DF G}.
B2:





B3:
Xut D = {R
1
, R
2
, R
3
}.
R(ABCDEFG)
R
1
(BA) R(DC) R
3
(DFG) R(DB) R(DE)
R
2
(DBCE)
45
V d phn r bo ton PTH (2)
Cho
R(ABCDEFGHI)
F = {B A, D C, D EB, DF G}
Tch v dng chun 3, bo ton PTH
B1:
Ph ti thiu G = {B A, D C, D B, D E, DF G}.
B2:



B3:
V U
1
U
2
U
3
= {ABCDEFG} nn t R
4
(HI).
B4:
D = {R
1
, R
2
, R
3
, R
4
}.
R(ABCDEFG)
R
1
(BA) R
3
(DFG) R
2
(DBCE)
46
Phn r khng mt thng tin (1)
Tnh cht khng mt thng tin
Xt lc R v tp PTH F. Gi s R c phn r
thnh D = {R
1
, , R
m
}.
D c gi l phn r khng mt thng tin i vi F nu vi
mi trng thi r e R th (t
R1
(r) * * t
Rm
(r)) = r.
nh l 3.3
Phn r D = {R
1
(U
1
), R
2
(U
2
)} ca R(U) khng mt
thng tin i vi tp PTH F nu v ch nu:
(U
1
U
2
) (U
1
U
2
) e F
+
, hoc
(U
1
U
2
) (U
2
U
1
) e F
+
.
47
Thut ton tch lc quan h tha BCNF
(T.Son Fischer 1982)
Thut ton 3.7
Nhp: R(U), U = {A
1
, , A
n
} v tp PTH F.
Xut: D = {R
1
, , R
m
}, R
i
dng chun Boyce-Codd.
B1:
D = {R};
B2:
Nu c lc Q(U
Q
) e D khng dng chun BC th
Tm X Y e t
Q
(F) lm Q vi phm iu kin BC.
D = (D - {Q}) Q
1
(U
Q1
) Q
2
(U
Q2
) vi U
Q1
= U
Q
- Y v U
Q2
= X Y.
Quay li B2.
Ngc li, chuyn sang B3.
B3:
Xut D.
48
V d phn r khng mt thng tin (1)
Cho:
R(ABCDEFG)
F = {B A, D C, D EB, DF G}
Tch v dng chun BC, khng mt thng tin.
D BCE
B A
R(ABCDEFG)
R
1
(BA) R
2
(BCDEFG)
R
3
(DBCE) R
4
(DFG)
F, K
R
= DF
{B A},
K
R1
= B
{D C, D EB, DF G},
K
R2
= DF
{D C, D EB},
K
R3
= D
{DF G},
K
R4
= DF
49
V d phn r khng mt thng tin (2)
D A
D BCE
R(ABCDEFG)
R
1
(DBCE) R
2
(ADEF)
R
3
(DA) R
4
(DFG)
F, K
R
= DF
{D BCE},
K
R1
= D
{D A, D E},
K
R2
= DF
{D A},
K
R3
= D
{DF G},
K
R4
= DF
50
Bi tp 1:
Cho lc quan h R(ABCDE) v tp ph
thuc hm:
F = {A -> B; C,D -> E; B -> C}
1. Tm mt kha ca lc .
2. Tm tt c cc kha ca lc .
3. Cho bit dng chun cao nht ca lc
trn? Nu cha t dng chun 3 hy tm
mt php phn r thnh cc lc con
t dng chun 3 v bo ton thng tin.
51
p dng cc bc tm bao ng ca tp cc
thuc tnh:
Lp 1: (BCDE)
F
+
= BCDE K = ABCDE.
Lp 2: (ACDE)
F
+
= ABCDE K = ACDE.
Lp 3: (ADE)
F
+
= ADEBC K = ADE.
Lp 4: (AE)
F
+
= AEBC K = ADE.
Lp 5: (AD)
F
+
= ADBCE K = AD.
AD l kho.
52
- Kha l AD, R khng t 2NF v A B
- Tm mt php phn r tch lc trn thnh cc lc
con t dng chun 3.
Cho lc quan h R(ABCDE) v tp ph thuc hm:
F = {A -> B; C,D -> E; B -> C}
V AD l kha v C l thuc tnh bc cu qua kho AD
AD -> B (khng tn ti B -> AD) v B -> C. (AD -> C)
Do ta tch nh sau:
R1(ADBE) R2(BC)
F1 = {A-> B } v F2 = {B -> C}
K1 = {ADE} K2 = {B}

53
Ta c R2 t dng chun 3, cn R1 th khng,
v thuc tnh khng kho B l bt cu qua
kho ADE, Do A -> B
Tch R1 thnh
R11(ADE) R12(AB)
K11= {ADE} K12 = {A}
F12 = {A -> B}