0

I had the question below in a past paper for relational databases. I am completely stuck on problem (iv). I think I may have done part (iii) wrong, which is leading to the issue.

Suppose you have the following database table called Songs:

Songs(singerID, singerName, songID, songName, songLength, songGenre)

where {singerID, songID} is a primary key and the following functional dependencies exist:

{singerID} -> {singerName}
{songID}   -> {songName, songLength, songGenre}
{songName} -> {songGenre}

i What normal form is the above table in?

Answer: It is in 1NF.

ii Say why it is not in 2NF.

Answer: SingerID does not determine songName, songGenre or songLength

iii Re-design the Songs table and make a table from it which is in 2NF.

Answer:

Singer{singerID, SingerName}
Song{SongID, songName, songLength, songGenre}
Songs{singerID, SongID}

Now I think all non-key attributes are functionally dependent on the primary key.

iv Say why the table you produced in part (iii) is in 2NF and not in 3NF. State any assumptions you need.

For me this is 3NF.

philipxy
  • 14,867
  • 6
  • 39
  • 83
SmC
  • 3
  • 5
  • What reference are you following? How can you be stuck if you are not following a reference procedure? What definitions are you using for 2NF & 3NF? – philipxy Jul 31 '17 at 08:26
  • Try the "Nothing but the key" definition. `songGenre` should depent on **nothing** but the key. But it depends on `songName`, which is **not** the key. – Paul Spiegel Jul 31 '17 at 12:51
  • @PaulSpiegel Such vague phrasings cannot be made precise, so are not definitions and are not helpful. – philipxy Aug 01 '17 at 01:16

2 Answers2

0

You have a transitive dependency: songID > songName > songGenre. This is tricky, since I wouldn't expect it in the real world.

For 3NF you'd need a table {songName, songGenre} and remove songGenre from song.

Paul Spiegel
  • 30,925
  • 5
  • 44
  • 53
  • Thanks Paul, I thought that, but is songGenre not FD in songID anyway, so is not transitive?! I am a bit confused.. and sonLength?! maybe I am missing something Thanks again – SmC Jul 30 '17 at 21:59
  • They say `{songID} > {songGenre}`. They **didn't** say that this dependency is not transitive :-) – Paul Spiegel Jul 30 '17 at 22:58
  • What matters is whether there are any transitive dependencies of non-prime attributes on CKs. – philipxy Jul 31 '17 at 09:29
0

What reference are you following? How can you be stuck if you are not following a reference procedure? What definitions & algorithms are you using for 2NF & 3NF?

i What normal form is the above table in?

Answer: It is in 1NF.

Question (i) doesn't make sense. Presumably they mean, what is the highest NF (normal form) this table is in. (In the list 1NF, 2NF, 3NF, ....)

Your answer to (i) doesn't make sense; every table in 2NF is also in 1NF. You mean it's in 1NF but not 2NF, or its highest NF is 1NF.

ii Say why it is not in 2NF.

Answer: SingerID does not determine songName, songGenre or songLength

Your answer to (ii) doesn't make sense; it doesn't appeal to a definition or algorithm for 2NF or higher.

iii Re-design the Songs table and make a table from it which is in 2NF.

Answer:

Singer{singerID, SingerName}
Song{SongID, songName, songLength, songGenre}
Songs{singerID, SongID}

Question (iii) doesn't make sense; normalization replaces a table by other tables. Maybe they meant something like "decompose it until you have a component that is in 2NF". But below I explain why they probably meant "make a design from it which is in 2NF".

Maybe you interpreted the question as "decompose it until you have a component that is in 2NF", agreeing with the first possible intent above. Or misinterpreted it as "make a bunch of tables from it which are 2NF", or, giving the same meaning, misinterpreted "table" as "design", agreeing with the second possible intent above. If the first, you don't say which component of yours is the answer, or that all of them are. Yours is a decomposition to all 2NF tables though.

iv Say why the table you produced in part (iii) is in 2NF and not in 3NF. State any assumptions you need.

For me this is 3NF.

Now I think all non-key attributes are functionally dependent on the primary key.

The two common definitions of 2NF are phrased in terms of not having any FDs of certain kinds that are said to be "in violation". One can always losslessly decompose in a certain way that gives smaller components where that FD is no longer a problem that can reasonably vaguely be referred to as "moving the FD to its own component, leaving another component". If you keep doing it then you would finally have all 2NF components--a 2NF design. (This is not part of good design, even to 2NF.) But if you "keep" a different one along the way then you "make" a different table that is "left". So there no particular table you would end up with unless you were told some some unusual way of decomposing in some ordered way. Moreover we can always decompose directly to 3NF, but question (iv) expects you not to do that.

Maybe question (iv) expects "the" table--assuming a certain definition, a certain kind of decomposition, and a certain ordering of decompositions. More likely question (iv) means "make a design from it which is in 2NF"--assuming a certain definition and a certain kind of decomposition.

Presumably you produced all 2NF tables via "moving" certain FDs per the above. (Non-trivial FDs with a nonprime attribute dependent on a proper subset of a CK). But your answer doesn't explain that. Moreover, PKs (primary keys) don't matter, CKs (candidate keys) do. If you mean there is only one CK in every table, you need to say so and justify it. But it still wouldn't/doesn't make sense, because it's not referring to a definition or algorithm for decomposition to 2NF or higher.

Your answer re 2NF vs 3NF doesn't make sense, you claim the tables are in 3NF and you are supposed to say why but you don't. (A reason Song is not in 3NF is its FD {songID} -> {songGenre} is a transitive dependency of a non-prime attribute on a CK via songName, or its FD {songName} -> {songGenre} is a dependency of a non-non-prime attribute on a non-superkey.

PS When we are given a PK or CK, certain FDs (functional dependencies) must hold, and certain FDs can't hold, and certain combinations of FDs can & can't hold. When given a set of FDs that hold, the set of all FDs that must hold when those do is given by Armstrong's axioms, ie the transitive closure of the given set. Usually questions that give an FD set mean that the only FDs that hold are those, ie that the set is a cover for the FDs in the table. Sometimes we're told it's a minimal cover. Various algorithms use various sets. Unfortunately lots of questions say the FDs in a set hold but it's not clear whether it's a cover, ie whether other FDs not in the transitive closure could hold. Just like this question!

(Please find out what the questions are trying to say, find a reference for definitions & procedures/algorithms, and follow it until you get stuck. Then ask a new question.)

philipxy
  • 14,867
  • 6
  • 39
  • 83
  • Thanks Philipxy.. We have not been talking about a reference procedure so I am not sure I follow you. The question was copied directly from the exam paper. Thanks – SmC Jul 31 '17 at 12:12
  • You were taught some stuff: definitions, facts & procedures. What do you think you have learned if not that? They are recorded somewhere. It is extremely likely that you have been given "references[/pointers]" to "reference[ material]s" such as textbooks, slides, etc. Maybe your only reference is your notes. The act of answering a question is the act of checking whether a definition applies or following another procedure. PS The exam question is a mess. Where is it from? A vendor? I would be interested in the composer's reaction to my answer. Alas database "education" is rife with confusions. – philipxy Jul 31 '17 at 12:39