Active Record/ORM 与普通形式?
我一直在使用 Active Record,我注意到 AC/ORM 在创建一对一关系时始终使用以下
数据库
模型国家/地区 ID |名称 | ...
国家/地区
ID |顶级域名 |名称 | ...
不,我想知道,这不是违反第三范式吗?这清楚地表明“每个非主要属性都非传递地依赖于表的每个键”。那么这个country_id不依赖于personid,是吗?
那么这是错误的还是我只是没有明白这一点?
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 non-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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
函数依赖,A => B,意味着根据定义,A 的每个不同值只能与 B 的单个值关联。换句话说,如果您知道 A,则 B 是给定的。在这种情况下,给定的
personid
只能与一个country_id
关联,因此personid =>国家ID
。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 onecountry_id
, thereforepersonid => country_id
.是的,有依赖性。
在关系代数中,每个表都有一个与之关联的谓词(即填充表中的值构成真实事实的语句)。
因此,例如“由
id
识别的人,来自国家country
,有一个名字name
,等等......”第三范式有时也表述为:“每个非主属性必须提供有关密钥、整个密钥的事实,并且除了密钥之外什么都没有。”
这就是说你正在寻找传递依赖。一个这样的例子是,
在这个例子中,tld 是传递依赖的 id,因为它依赖于country_id,而country_id又依赖于id。因此,这个例子违反了 3NF。
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 countrycountry
, has a namename
, 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
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.