BCNF/3NF in Relational Databases
-
10-02-2021 - |
Pregunta
How do you tell if a relation R is in BCNF and 3NF?
I'm reading a textbook, and it's telling me that there are 3 main attributes you're looking at, but I'm having trouble understanding what they're saying, or at least applying what they're saying when given a relation and FD's.
The 3 attributes: Given a relation R with the attribute A, and X a subset of attributes of R, for every FD X⟶A in F, one of the following statements is true:
- A ∈ X; that is, it is a trivial FD (∈ meaning "is found in X")
- X is a superkey
- A is part of some key for R
The top two correspond to BCNF, and 3NF's include the third.
Solución
The book SQL Antipatterns by Bill Karwin has a nice example about BCNF and 3NF on page 303 that is a little complicated but I believe points out the difference more succinctly than any description of the difference I've read so far.
For example, suppose we have three tag types: tags that describe the impact of the bug, tags for the subsystem the bug affects, and tags that describe the fix for the bug. We decide that each bug must have at most one tag of a specific type. Our candidate key could be
bug_id
plustag
, but it could also bebug_id
plustag_type
. Either pair of columns would be specific enough to address every row individually.bug_id tag tag_type ------------------------ 1234 crash impact 3456 printing subsystem 3456 crash impact 5678 report subsystem 5678 crash impact 5678 data fix
The book then changes this single table (which satisfies 3NF) into two tables that satisfy BCNF:
bug_id tag ---------- 1234 crash 3456 printing 3456 crash 5678 report 5678 crash 5678 data tag tag_type ------------------ crash impact printing subsystem report subsystem data fix