A relation schema R is in BCNF wrt a set of FD's F over R, iff whenever
and
, X is a superkey.
BCNF Example [267]
BAD(S#,P#,NAME,CITY,XNAME,YCITY,QTY)
is not in BCNF wrt
since the first two are not superkeys since the key is SP.
Decompose:
S(S#,CITY,NAME) is in BCNF wrt
P(P#,XNAME,YCITY) is in BCNF wrt
SP(S#,P#,QTY) is in BCNF wrt
In fact, this is the same decomposition as the 3NF algorithm would yield.
If its in BCNF, then its in 3NF but not vice versa.
Algorithm to Decompose into BCNF [268]
Input: Relation schema R and FD's F
Output: A BCNF decomposition of R with lossless join
Method:
BCNF Example [269]
R = (ABCDE) and
Key: AC,BC
1. A 3NF Decomposition
ABCD,
with Keys AC,BC is 3NF since A,B are primes
Not in BCNF.
ABE,
with Keys A,B is in 3NF and is in BCNF
2. Use Algorithm for producing 3NF
which yields (AB,BE,ACD) which contains the key AC
This is 3NF and BCNF.
BCNF Example - continued [270]
Now use the BCNF algorithm.
| ABCDE |
|
|
| Key: AC,BC |
The first one violates BCNF, branch it off.
| AB |
|
|
| Key: A,B |
| ACDE |
|
|
| Key: AC |
violates, branch it off
| AE |
|
|
| Key: A |
| ACD |
|
|
| Key: AC |
Answer: (AB,AE,ACD) Lossless Join?
Preserve
?
YES.
BCNF Example [271]
Billto = (AIRPORT,COMPANY,OFFICE)
If someone from company C charges a ticket at airport A, then send the bill to office O.
| AIRPORT | COMPANY | OFFICE |
| lax | ibm | ibmsdbranch |
| sd | ibm | ibmnyoffice |
| pitt | ibm | ibmsdbranch |
Key: AO,AC
is already in 3NF since C is prime.
But there are duplicate CO pairs, would like to separate.
BCNF alg:
| ACO | ||
|
|
||
| Key: AO,AC |
Branch off
| OC | ||
|
|
||
| Key: O |
| AO | ||
| Key: AO |
has not been preserved.
BCNF and 3NF Decomposition [272]
Repeat of the last example:
| ABCDE | ||
|
|
||
| Key: AC |
| AB | ||
|
|
||
| Key: A,B |
| ACDE | ||
|
|
||
| Key: AC |
| AE | ||
|
|
||
| Key: A |
| ACD | ||
|
|
||
| Key: AC |
BCNF Answer: (AB,AE,ACD)
3NF:
Yields (AB,BE,ACD) with the key AC already contained.
University Example Again [273]
| CTHRSG | ||
|
|
||
| Key: HS |
| CSG | ||
|
|
||
| Key: CS |
| CTHRS | ||
|
|
||
| Key: HS |
| CT | ||
|
|
||
| Key: C |
| CHRS | |||
|
|
|||
|
|
|||
| Key: HS |
| CHR | ||
|
|
||
| Key: CH,HR |
| CHS | ||
|
|
||
| Key: HS |
BCNF: (CSG,CT,CHR,CHS)
is not preserved
Summary of Design [274]