chap6 (1)
chap6 (1)
Comp 231
231 Database
Database Management
Management
Systems
Systems
6. Integrity Constraints
• Domain Constraints
• Referential Integrity
• Assertions
• Triggers
• Functional Dependencies
R1 ( K1, …, … ) R2 ( K2, …, , … )
t2
x
t1
x
works-
Works-for ( employee-no, dept-no) Primary key
Emp for Dep of Works-for
Foreign keys
loan-info
Another example: branch-nm loan-no cust-nm amount
reverse of the fd’s above Perryridge L-001 Peter Yeung 100000
Perryridge L-001 Peter Yeung 100000
Central L-001 Peter Yeung 250000
Wanchai L-002 Leon Lai 100000
– if , then (reflexivity)
– if , then (augmentation)
– if and , then (transitivity)
– if , then (augmentation)
loan-no amount (given)
loan-no, branch-name amount, branch-name
• R = (A, B, C, G, H, I)
• F = {A B
A C
CG H
CG I
B H}
• some members of F+
A H A B; B H
AG I A C; AG CG; CG I
CG HI
If loan-no branch-name
then branch-name is part of loan-no+
I.e., loan-no+= loan-no,amount, branch-name …
• R = (A, B, C, G, H, I)
F= ( A B
A C
CG H
CG I
B H}
• (AG+)
1. Result= AG
2. Result= ABCG (A C; A B and A
AG)
3. Result= ABCGH (CG H and CG
AGBC)
4. Result=ABCGHI (CG I and CG result contains all
AGBCH) of the attributes
• Is AG a candidate key? of R, so stop
1. AG R
2. Does A+ R? Question: What is A+ and G+ ?
3. Does G+ R?
Department of Computer Science and Engineering, HKUST
Slide 36
Canonical
Canonical Cover
Cover
• Consider a set F of functional dependencies and the functional
dependency in F.
– Attribute A is extraneous in if A and if A is removed from , t
he set of functional dependencies implied by F doesn’t AC
change.
From
Given AB C and A C then B is extraneous in AB I get AB C
– Attribute A is extraneous in if A and if A is removed from , t
he set of functional dependencies implied by F doesn’t change.
Given A BC and A B then B is extraneous in BC
• A canonical cover Fc for F is a set of dependencies such that F l
ogically implies all dependencies in Fc and Fc logically implies a
ll dependencies in F, and further
– No functional dependency in Fc contains an extraneous attribute.
– Each left side of a functional dependency in F c is unique.
• R = (A, B, C)
F={ A BC
A BC
B C
B C
A B
AB C
AB C}
• Combine A BC and A B into A
A BC
BC A BC
B C
• A is extraneous in AB C because B C B C
B C logically implies AB C.
• C is extraneous in A BC since A A B
BC is logically implied by A B and B C
B C.
• The canonical cover is:
AB
BC
Department of Computer Science and Engineering, HKUST
Slide 39
Example
Example
• R = (A, B, C, G, H, I)
F={ AB
AC
CG H
CG I
B H}
• some members of F +
– AH
• by transitivity from A B and B H
– AG I
• by augmenting A C with G, to get AG CG
and then transitivity with CG I
– CG HI
• from CG H and CG I : “union rule” can be inferred from
– definition of functional dependencies, or
– Augmentation of CG I to infer CG CGI, augmentation of
CG H to infer CGI HI, and then transitivity