Odd BCNF Decomposition on my past exam - database-normalization

I have a problem breaking this into BCNF:
Relation: R[A E P M N S T L]
FD's:
A -> EM,
A -> L,
M -> ST,
M -> N,
S -> T,
E -> P,
P -> E,
L -> A
This one was on one of my past exams, and I don't really know how to solve it.
I learned this on coursera by the woman (Jennifer Widom) who wrote our course literature:
-------------- BCNF ALGORITHM ------------
1. Take a FD that violates BCNF.
2. Decompose the FD to two other relations
3. First relation: The whole FD
4. Second relation: The rest of the Relation + the left hand side of the chosen FD
5. Iterate until all the new relations have key on its left hand side
-------------- BCNF ALGORITHM ------------
And I also tried another one that is basically the same, but written in a different way:
X->Y: R1({X}+), R2(R - {X}+ ; X) (Relation minus {X}+ (XY in this case), plus X.
So far, I'm here:
Obviously, A is key, so its FDs are already in BCNF. Question is, can I erase any redundant FDs maybe? If so, what is the thumb rule?
R1(MST) <-- BCNF.
R2(A E P M N L)
R3()
And have no idea where to go.

1. Take a FD that violates BCNF.
5. Iterate until all the new relations have key on its left hand side
Step 1 in mentioning BCNF violation can only make sense if it means you should identify the keys and non-key-implied FDs of each original and generated relation. Also, step 5 termination cannot be merely when there is a key on the left hand side, because a non-key determiner could be present. Clearly it is necessary and sufficient to stop when all relations are in BCNF. A particular full description of an algorithm may describe equivalent reorganizations and/or tests without explicitly mentioning BCNF.
If A is a key then so is L since L->A.
MSTNAELP keys A and L plus M->ST, S->T, E<->P
Those FDs are from non-keys. You picked M->ST. We get:
MST key M plus S->T
MNAELP keys A and L plus E<->P
Both have determiners not from keys, hence are not in BCNF. Pick S->T and E->P. We get:
ST key S in BCNF
SM key M in BCNF
EP keys P and E in BCNF
EMNAL keys A and L in BCNF

Related

Could someone please give me an example of a 3NF *DECOMPOSITION* that is not in BCNF? (I have no problem determining this for non-decompositions.)

It seems to me that Bernstein's synthesis / 3NF synthesis always yields BCNF subrelations, but that's apparently not true.
When one uses 3NF synthesis, one will have subrelations as a result, and they will each consist of either:
just one functional dependency along with all attributes of the schema, so the left side of the lone functional dependency will be a superkey, and that subrelation will therefore be in BCNF.
multiple functional dependencies each of which have the same left side, so they're each superkeys, and that subrelation will therefore be in BCNF.
no functional dependency where the schema includes the attributes making up the primary key of the original / non-decomposed relation, which would satisfy BCNF vacuously because of there being no functional dependencies.
What is an example of the 3NF synthesis algorithm yielding a non-BCNF decomposition and why it is so?
Bernstein's algorithm returns (one or more) components in EKNF, which lies between 3NF & BCNF.
Your claims of "that subrelation will therefore be in BCNF" are wrong. The FDs that hold in a component are all the ones in the closure of the original relation whose attributes are all in the component. So FDs could hold in a component that are not out of its superkeys. (Which by definition of BCNF is just another way of saying a component could be not in BCNF. Obviously--since we are told that the algorithm doesn't always give BCNF.)
Since your reasoning is unsound, finding a counterexample seems moot. But just about any presentation of BCNF gives an example non-BCNF 3NF relation, which it then decomposes to BCNF. You can join the non-BCNF 3NF relation with a projection on attributes of one of its CKs extended by a fresh non-prime attribute, and Bernstein's algorithm can decompose back to the 2 tables.
Chris Date's classic An Introduction to Database Systems has a non-BCNF 3NF schema R(S, J, T) with minimal/irreducible cover
{S, J} -> T
{T} -> J
CKs are {S, J} & {T, J}. Berstein gives component (S, J, T)--non-BCNF 3NF input R--in which both given FDs hold--plus redundant component (T, J).
For an example with an additional non-redundant component, extend the cover by {T} -> X. CKs are the same. {S, J} -> T again gives (S, J, T)--non-BCNF--plus component (T, J, X).
So, could someone please give me an example of the 3NF synthesis algorithm yielding a non-BCNF decomposition and tell why it is so?
A better "So, [...]" would be, So, what is wrong with my reasoning? You would do well to examine the assumptions you made about what FDs could hold in a component. (That article happens to point out (with reference) that "A 3NF table that does not have multiple overlapping candidate keys is guaranteed to be in BCNF.")
There is no "why" in mathematics. We assume things ("assumptions", "axioms", "premises") & other things follow. We can ask for a proof of something, but the proof does not say "why" the something is so, it's a demonstration that it is so. "Why" might be used trying to ask for a proof or for steps that you got wrong in or are missing from whatever almost-proof you have in mind.
PS Such a ubiquitous non-BCNF 3NF relation is Today's Court Bookings in the Wikipedia article on BCNF as I write. But beware that that particular example has perhaps unintuitive FDs. Indeed beware that almost every relational model Wikipedia page--including that one--has errors & misconceptions. So do many, many textbooks, especially re normalization.
The answer of philipxy is correct. Since you are asking for an example, here there are a couple of them.
The relation (with a cover of the functional dependencies):
R (A B C D)
A B → C
C → D
D → B
through the synthesis algorithm is decomposed in:
R1 (A B C)
R2 (C D)
R3 (B D)
and R1 is not in BCNF for the dependency C → B (the candidate key is AB). Note that C → B is not present in the original cover, but is a dependency implied from it.
Here is another (classical) example:
Phones (AreaCode, PhoneNumber, Subscriber, Town, Street)
AreaCode, PhoneNumber → Town
AreaCode, PhoneNumber → Subscriber
AreaCode, PhoneNumber → Street
Town → AreaCode
The Bernsteins’s synthesis algorithm produces two subschemas:
R1 (AreaCode, PhoneNumber, Subscriber, Town, Street)
AreaCode, PhoneNumber → Town
AreaCode, PhoneNumber → Subscriber
AreaCode, PhoneNumber → Street
and:
R2 (Town, AreaCode)
Town → AreaCode
since R2 is included in R1, the algorithm eliminates the second relation. The resulting relation is in 3NF but not in BCNF, since the relation has two candidate keys, (AreaCode, PhoneNumber) and (PhoneNumber, Town) and the functional dependency Town → AreaCode violates the BCNF.

Convert a relation into BCNF

R (A B C)
AB -> C,
C -> A
AB is the minimal super key which is a candidate key.
AB -> C is good.
But C -> A doesn't hold good since prime attribute depends on Non Prime attribute. I know how to decompose till 3 NF. I also know why relation is not in BCNF.
But I don't know how to break this relation into BCNF. How can I do that?
This relation can be decomposed in BCNF using for instance the analysis algorithm, which produces the following decomposition:
R1(A, C) (with non trivial dependency C → A and candidate key C)
R2(B, C) (without non trivial dependencies and so with candidate key (B, C))
But this decomposition does not preserve the dependencies: in fact, the dependency A B → C is lost. So, with such decomposition, the constraint due to this dependency cannot be simply enforced on the decomposed relations. And no other decomposition in BCNF can be produced such that the dependencies are maintained. We can note also that the relation is already in 3NF.

What is the correct approach when decomposing dependencies

I am struggling with Carnonical Cover, Dependency Preservation and Lossless Decomposition.
Are the approach and thoughts here correct?
R(ABCDEFG)
Provided is the following set of dependencies after a canonical cover has been made. I did not do the canonical cover myself but the assignment said I had to assume it had been done.
Fc:
A -> C
E -> A
C -> ABF
F -> CDG
A+ = ABCDFG
E+ = ABCDEFG
C+ = ABCDFG
F+ = ABCDFG
E = Candidate Key.
This list of functional dependencies is in 2NF since there are no partial dependencies. It is however not in 3NF since there are transitive dependencies.
However decomposing into the following 4 relations will result in it being not only in 3NF but also BCNF
R1 = {E,A}
E -> A
R2 = {A, C}
A -> C
R3 = {CABF}
C -> ABF
R4 = {FCDG}
F -> CDG
I use A in R1 as a foreign key to R2 and C in R2 as a foreign key to R3 etc.
There are no transitive dependencies and since all left hand sides are candidate keys in their respective relations it is in BCNF.
Is also lossless and dependency preserving?
What is decomposed
In the title you say:
What is the correct approach when decomposing dependencies
but one does not decompose dependencies, but relation schemas. So, in this case, here there is a relation schema R(ABCDEFG) with a set of functional dependencies and one must decompose that schema.
What is a decomposition
A decomposition produces a set of relation schemas with the following properties: a) every attribute of the original schema is present in some (possibly more than one) subschema; b) no other attributes are present. Moreover, a decomposition is redundant when a relation subschema is contained in another. In your case, this is true for R2, which is contained in R3: there is no need to have both relations, since it would imply unuseful data redundancy.
What is a good decomposition
To be really useful, a decomposition should satisfy two important properties: preserve functional dependencies and preserve data (lossless decomposition). But another property characterizes a good decomposition: it should be as small as possible: there is no point in decomposing a schema in too many subschemas, since this would produce a non natural and complex database.
Actually your decomposition is lossless and preserves the dependencies.
How to decompose
The final objective of all this stuff is to produce a decomposisition (lossless and dependency preserving) in which the subschemas are in BCNF or 3NF. The simple solution of decomposing by using the attributes of the functional dependencies is not, however, a good solution. For this, there are algorithms, described in textbooks, that produces decompositions either for BCNF or for 3NF (the so-called “analysis” algorithm for BCNF, and “synthesis” algorithm for 3NF), trying to produce not too many subschemas. For instance, the “analysis” algorithm in this case produce the following decomposition in BCNF, with only two subschemas:
R1 < (A B C D F G) ,
{ F → C
F → D
F → G
C → A
C → B
C → F
A → C } >
R2 < (A E) ,
{ E → A } >
This decomposition is lossless and preserves the dependencies (which is not always true for the analysis algorithm).

Decomposition into ABC & CDE and preserving functional dependencies

Consider a relation R with five attributes ABCDE. Now
assume that R is decomposed into two smaller relations ABC and CDE.
Define S to be the relation (ABC NaturalJoin CDE).
a) Assume that the above decomposition is lossless join. What is the
dependency that guarantees the lossless join property.
b) Give an additional FD such that “dependency preserving” property is
violated by this decomposition.
c) Give two additional FD's that would be preserved by this
decomposition.
Question seems different to me because there is no FD given and its asking:
a)
R1=(A,B,C) R2=(C,D,E) R1∩R2 =C (how can i control dependency now)
F1' = {A->B,A->C,B->C,B->A,C->A,C->B,AB->C,AC->B,BC->A...}
F2' = {C->D,C->E,D->E....}
then i will find F' ??
b,c) how do i check , do i need to look for all possible FD's for R1 and R2
The question is definitely assuming things it hasn't said clearly. ABCDE could be subject to the JD *{ABC,CDE} while not being subject to any nontrivial FDs at all.
But suppose that the relation is subject to some FDs and isn't subject to any JDs other than ones that they imply. If C is a CK then the join is lossless. But then C -> ABCDE holds, because a CK determines all attributes, and C -> ABDE holds, because a CK determines all other attributes. No other FD holding would imply that the join is lossless, although that requires tedium (by looking at every possible case of CK) or inspiration to show.
Both these FDs guarantee losslessness. Although if one of these holds the other holds, and they express the same condition. So the question is sloppy. Or the question might consider that the two expressions express the same FD in the sense of a condition, but a FD is an expression and not a condition, so that would also be sloppy.
I suspect that the questioner really just wanted you to give some FD whose holding would guarantee losslessness. That would get rid of the complications.

Decide whether a relationship is in BCNF

I check the definition on Wikipedia for BCNF
A relational schema R is in Boyce–Codd normal form if and only if for every one of its dependencies X → Y,
at least one of the following conditions hold:[4]
X → Y is a trivial functional dependency (Y ⊆ X)
X is a superkey for schema R
Now if R={P,Q,S}
and F={PQ->S, PS->Q, QS->P}
I think it is not in BCNF, am I right?
If I am wrong, could you give me some idea why?
Otherwise, if we are asked that which FD violates the BCNF, since any determinant in FD could be the superkey, what should we give?
Informally, a relation is in BCNF if every arrow for every FD is an arrow out of a candidate key. In this case, the candidate keys are PQ, PS, and QS, so every arrow is an arrow out of a candidate key. I think it's in BCNF.