单个表中的列太多 - 这是好的范式​​吗?

发布于 2024-07-13 01:19:37 字数 72 浏览 5 评论 0原文

规范化表应该具有较少数量的列,并且可以具有尽可能多的引用字段。 这是正确的做法吗? 列数和良好的标准化过程之间有什么关系吗?

A normalized table should have less number columns and can have reference fields as much as possible. Is it right approach?
Is there any relationship between number of columns and a good normalization process?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(5

泡沫很甜 2024-07-20 01:19:38

两者之间有什么关系吗?
列数和良好的
标准化过程?

简而言之,不。 3NF 规范化表将具有所需数量的列,前提是

表中的数据是相关的
在钥匙上,整个钥匙,什么也没有
但关键(所以帮助我科德)。

在某些情况下,(某些)非规范化实际上可能会提高性能,而衡量何时应该这样做的唯一真正衡量标准是对其进行测试。

Is there any relationship between
number of columns and a good
normalization process?

In short, no. A 3NF normalized table will have as many columns as it needs, provided that

data within the table is dependent
on the key, the whole key, and nothing
but the key (so help me Codd).

There are situations where (some) denormalization may actually improve performance and the only real measure of when this should be done is to test it.

请别遗忘我 2024-07-20 01:19:38

您应该遵循规范化原则,而不是关心表中的列数。 业务需求将驱动实体、实体的属性及其关系,并且没有绝对的数字是“正确的”数字。

You should follow the normalization principles rather than be concerned with the sheer number of columns in a table. The business requirements will drive the entities, their attributes and their relationship and no absolute number is the "correct" one.

指尖上得阳光 2024-07-20 01:19:38

如果您觉得表的字段太多,可以使用以下方法。 示例:-

CREATE TABLE Person
    Person_ID int not null primary key,
    Forename nvarchar(50) not null,
    Surname nvarchar(50) not null,
    Username varchar(20) null,
    PasswordHash varchar(50) null

该表代表人员,但显然并非所有人员都需要成为用户,因此 Username 和 PasswordHash 字段可为空。 然而,人数可能比用户多 1 或 2 个数量级。

在这种情况下,我们可以创建一个 User 表来保存 Username 和 PasswordHash 字段,并与 Person 表建立一对一的关系。

您可以通过查找可空字段集来概括此方法,这些字段要么一起为空,要么一起具有值并且很可能为空。 这表明您还可以提取另一个表。

编辑

感谢斯蒂芬妮(参见评论),这种技术显然被称为“垂直分区”

Here is an approach you can use if you feel your table has too many fields. Example:-

CREATE TABLE Person
    Person_ID int not null primary key,
    Forename nvarchar(50) not null,
    Surname nvarchar(50) not null,
    Username varchar(20) null,
    PasswordHash varchar(50) null

This table represents people but clearly not all people need be users hence the Username and PasswordHash fields are nullable. However its possible that there will be 1 or 2 orders of magnitude more people than there are users.

In such case we could create a User table to hold the Username and PasswordHash fields with a one-to-one relationship to the Person table.

You can generalise this approach by looking for sets of nullable fields that either null together of have values together and significantly likely to be null. This indicates that there is another table you could extract.

Edit

Thanks to Stephanie (see comments) this technique is apparently called "Vertical Partitioning"

你列表最软的妹 2024-07-20 01:19:38

虽然我同意@ocdecio,但我还观察到,在给定相同的数据存储要求的情况下,标准化的数据库通常比未标准化的数据库每个表具有更少的列和更多的表。 与代码气味类似,对于相当大的应用程序,数据库气味将是相对较少的表。 这暗示您的数据可能不是正常形式。 在适当的情况下应用标准化规则可以减轻这种“气味”。

While I agree with @ocdecio, I would also observe that a database that is normalized will generally have fewer columns per table and more tables than one that is not, given the same data storage requirements. Similar to code smells a database smell would be relatively few tables given a reasonably large application. This would be a hint that perhaps your data is not in normal form. Applying normalization rules, where appropriate, would alleviate this "smell".

感情废物 2024-07-20 01:19:38

每列必须与主键有直接且排他的关系。 如果您有一个属性较多的项目,那么您只能做这么多来简化模型。 任何拆分成多个表的尝试都会适得其反并且毫无意义。

Each column must have a direct and exclusive relationship to the primary key. If you have an attribute-heavy item that there is only so much you can do to simplify the model. Any attempt to split into multiple tables will be counter-productive and pointless.

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