mysql - 多少列太多了?

2021-11-20 00:00:00 sql mysql

我正在设置一个可能有 70 列以上的表格.我现在正在考虑将其拆分,因为每次访问表时都不需要列中的某些数据.再说一次,如果我这样做,我就不得不使用连接.

I'm setting up a table that might have upwards of 70 columns. I'm now thinking about splitting it up as some of the data in the columns won't be needed every time the table is accessed. Then again, if I do this I'm left with having to use joins.

在什么时候(如果有)被认为是太多列?

At what point, if any, is it considered too many columns?

推荐答案

一旦超过数据库支持的最大限制.

您不需要每个查询都返回每一列的事实是完全正常的;这就是为什么 SELECT 语句让您明确命名所需的列.

The fact that you don't need every column to be returned by every query is perfectly normal; that's why SELECT statement lets you explicitly name the columns you need.

作为一般规则,你的表结构应该反映你的领域模型;如果您确实有 70 个(100 个,您有什么)属于同一实体的属性,则没有理由将它们分成多个表.

As a general rule, your table structure should reflect your domain model; if you really do have 70 (100, what have you) attributes that belong to the same entity there's no reason to separate them into multiple tables.

相关文章