开发者

Active Record/ORM vs Normal Forms?

I've been playing around with Active Record a bit, and I have noticed that A.C./ORM always uses the following database model when creating a one-to-one relationship

Person

id | country_id | name | ...

Country

id | tld | name | ...

No I wondered, isn't this a violiation of the third Normal Form? This clearly states "Every n开发者_运维百科on-prime attribute is non-transitively dependent on every key of the table". Well this country_id isn't dependent of personid is it?

So is this wrong or am I just not getting the point?


A functional dependency, A => B, means that each distinct value of A can, by definition, only be associated with a single value of B. In other words, if you know A, then B is a given. In this case, a given personid can only be associated with one country_id, therefore personid => country_id.


Yes, it is dependant.

In relational algebra, every table has a predicate associated with it (that is the statement that filled with values from table make a true fact).

So, for example "Person identified by id, comes from country country, has a name name, etc..."

The 3rd normal form is also sometimes phrased as: "Every non-prime attribute must provide a fact about the key, the whole key, and nothing but the key."

Which is to say that you are looking for transitive dependencies. An example of this would be

Person (id, country_id, tld, name, ...)

In this example tld is transitively dependant id, because it is dependant on country_id, which is dependant on id. So, this example would violate 3NF.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜