简体   繁体   中英

Third (?) normal form of a relation

Let's say I have a website, where any person can buy and sell items and 2 registered users can send messages to each other regarding a product. One of the relations in my database is:

Message
--------
idMessage (PK)
Sender
Recipient
idObject
Subject

Of course one of the sender or the recipient should be either the seller or the buyer of a product. My question is if this relation is in 3rd normal form. Of course it is in 2nd normal form, because every non - key column is fully functionally dependent on the primary key.

Example: Let's say that userB is the seller(owner) of the product #1234 and userA is the seller(owner) of the product #1000 . We have the following table:

idMessage| Sender| Recipient | idObject| Subject
________________________________________________
    1    | userA |   userB   | #1234   | size  
    2    | userB |   userC   | #1234   | discount
    3    | userA |   userB   | #1000   | size

Apparently, idObject in the above table determines the seller of the product. In each case the seller must be either in the "Sender" column or in the "Recipient" column. The point is the [Sender] or/and [Recipient] cannot determine the idObject, as we can see in the example above. Thus, we have 3NF, since all the non - key columns are functionally depedent only and only on the primary key.

So, the question should be, is there a transitive functional dependency? if the answer is yes, then this is not a 3NF.

Not sure if I completely understand the idObject attribute, but if [idMessage] determines [idObject] via [Recipient] or [Sender] then we have a transitive functional dependency hence this would not be a 3NF. If [idObject] is determined by the [idMessage] attribute then all non-key attributes are fully functional dependent only on the primary key [idMessage] and this would be a 3NF.

You may want to add some explanation on What is idObject ? Hope this helps.

You are misusing the term "determines".

An attribute set determines another when a subrow value for the first only ever appears with at most one subrow value of the other. Since idObject can appear with multiple values of Sender and multiple values of Recipient, it doesn't functionally determine either of them.

Your description and common sense don't suggest any functional dependencies hold other than the ones implied by idMessage being PK. So this is in 3NF and BCNF.

In fact if I give you an idObject value you can't tell me anything at all about what this table looks like other than what its heading and idMessage being PK tell you. So it's in 5NF. (And DKNF.)

(I can't even figure out a definition of "determines" that makes sense of what you write. Maybe you consider the owner of an object to be involved in "determining". If you required that either the sender or recipient of a message its object's owner then whenever an idObject value appeared there would have to be a single value that appears in every (Sender, Recipient) subrow as either Sender or Recipient. But that constraint is not a functional dependency and it doesn't imply that there is a functional dependency. So the relation would still in 3NF.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM