Active Record/ORM 与普通形式?

发布于 2024-09-01 02:32:42 字数 256 浏览 3 评论 0原文

我一直在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

╄→承喏 2024-09-08 02:32:42

函数依赖,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 one country_id, therefore personid => country_id.

踏雪无痕 2024-09-08 02:32:42

是的,有依赖性。

在关系代数中,每个表都有一个与之关联的谓词(即填充表中的值构成真实事实的语句)。

因此,例如“由id识别的人,来自国家country,有一个名字name,等等......”

第三范式有时也表述为:“每个非主属性必须提供有关密钥、整个密钥的事实,并且除了密钥之外什么都没有。”

这就是说你正在寻找传递依赖。一个这样的例子是,

Person (id, country_id, tld, 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 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文