问题
So to sum it all up, i am having major difficulties understanding functional dependencies just by looking at abstract examples and would really appreciate some help of understanding with possible real life situations. I want to see if these functional dependencies is any BCNF violation. I have read alot of explainations but im still struggling with understanding fully and i cannot understand the full picture only by looking at characters such as the below. I feel like i need some real data to think of, and therefor my examples below.
R(A,B,C,D,E) where functional dependencies are AB -> C, DE -> C, and B -> D.
I am trying here with different examples and scenarios and got this. Not sure if im thinking totally wrong. But here i go.
Employee(employee_id, firstname, lastname, title, department)
AB -> C, employee_id, firstname -> lastname (lastname can be determined by employee_id and firstname). lefthand side is a key so no bcnf violation?
DE -> C, title, department -> lastname (lastname of specific employee can NOT be determined by title and department. a bcnf violation, because lefthand side contain no key attribute?
B -> D, firstname -> title (title of employee can not be determined by only firstname, because it can exist several employees with same firstname? and lefthand side has no key attribute, => bcnf violation?
My question now is, these FD for the above relation, MUST it be the same result on every example that i test with? Or does it depend on each relation and what attributes they have, and in which order?
If i try another example with the same FD and relation.
Movie(movieName, published, starName, age, address)
movieName, published -> starName (starnName can be determined from movieName and published. no bcnf violation?
age, address -> starName (starName cannot be determined from age and address. bcnf violation?
published -> age (age of the movie can be determined from published. No bcnf violation?
I would really really appreciate some guidance.
Thanks.
回答1:
You do not understand the definitions of "functional dependency" or "BCNF". You need to memorize the definitions, including the definitions of the terms that the definitions use.
Functional dependency is not about "determining" one thing from another in some everyday sense.
In a given table a FD holds when each subrow value for the determinant attribute set always appears with the same subrow value for the determined attribute set. A table is in BCNF when every determinant of a non-trivial FD is a superkey. (Learn the definitions of those terms.)
In practice we determine what columns are functionally determined by other columns for a given table, then do the math, then use what comes out. There's not much to learn from a complicated example. Each example table you give in your question has a certain meaning and, given what situations arise, it does not have that set of FDs. Using common sense, in Employee, employee_id determines all attributes, and probably no other FDs hold other than the ones that must hold when those ones do. Using common sense, in Movie, many movies can have the same name and the only FDs are {published} -> {age} and those that follow from it.
Any time you do have a relation "R(A,B,C,D,E) where functional dependencies are AB -> C, DE -> C, and B -> D" and those that they imply (presumably R, A, B, C, D & E are placeholders for the actual names) then the candidate keys and superkeys and whether it is in BCNF and how you can decompose it will always be the same (in terms of A, B, C, D & E).
来源:https://stackoverflow.com/questions/41017622/functional-dependencies-examples