简体   繁体   English

您应该在多少列中创建另一个表?

[英]At what number of columns should you make another table?

I had a table that nearly reached 20 columns. 我有一张几乎达到20列的桌子。

I find each one necessary since it's a "project" table, and the project has columns that indicate stuff such as when it was created, when it was updated, its id, who started it, who finished it, some metadata such as keywords, the content of the project itself, a brief description and some other stuff. 我发现每个都是必要的,因为它是一个“项目”表,项目中有列表示诸如创建时间,更新时间,ID,启动时间,完成时间,关键字等元数据之类的内容。项目本身的内容,简要说明和其他一些东西。

I was happy with my table, but then I browsed some questions through stackoverflow and saw stuff like "your table should never have more than 10 columns" and suggestions that if it was the case, you should split your table into smaller ones. 我对我的桌子很满意,但后来我通过stackoverflow浏览了一些问题,看到了“你的桌子永远不会超过10列”这样的东西,并建议如果是这样的话,你应该将你的桌子分成小桌子。

Following StackOverflow's advice, I split my table into two tables, but I'm finding it more complicated to manipulate. 按照StackOverflow的建议,我将表分成两个表,但我发现操作起来更复杂。 Now, when each project is created, I have to create two new records, each one for each table. 现在,当创建每个项目时,我必须创建两个新记录,每个记录对应一个表。 I have to handle errors on the creation of either record, which means that if the creation of the record on the second table fails, I have to do yet another query to rollback the creation of the first record. 我必须在创造记录或者,这意味着如果在第二个表中的记录的创建失败,我必须做另一个查询回滚的第一条记录的创建的处理错误。 Data retrieval and record deletion has also been made more complex, since now I have to do that on two tables. 数据检索和记录删除也变得更加复杂,因为现在我必须在两个表上执行此操作。

I'm using the Sails.js framework, and trying to use associations, but I find that it's pretty much the same, I still have to repeat tasks for each table. 我正在使用Sails.js框架,并尝试使用关联,但我发现它几乎相同,我仍然需要为每个表重复任务。

Is it really worth it to split your table into smaller ones if it gets that big? 如果它变得那么大,将你的桌子分成小桌子真的值得吗? Or should I just keep my 20 column table? 或者我应该保留我的20列表? My project is new, not even online, so I don't know performance. 我的项目是新的,甚至不在线,所以我不知道性能。 I've never understood associations/joins or databases in general, as in, I've never understood why people do it, so, what are the benefits? 我从来没有理解一般的关联/联接或数据库,因为我从来不理解为什么人们这样做,所以,有什么好处?

Keep your 20 column table, to be honest 20 columns is not a lot considering 5 columns are taken, as you tell, by who when (created, edited) and the ID. 保持你的20列表,老实说20列并不是很多,考虑到5列,正如你所知,由何时(创建,编辑)和ID。

There are other considerations when designing a database table, the number of columns should not be a priority. 在设计数据库表时还有其他注意事项,列数不应该是优先级。 You can think about splitting it into multiple tables when you have some performance issues but for now keep your table. 当您遇到一些性能问题时,可以考虑将其拆分为多个表,但现在请保留您的表。 Go to 40 columns and still you should not care. 转到40列,你仍然不应该关心。

The person that said never more then 10 was either talking about some performance issues that can be addressed, or it was a specific case where it made a difference or has some strange "standards". 那个说不超过10的人或者要么谈论一些可以解决的性能问题,要么是一个特殊情况,它会产生影响或者有一些奇怪的“标准”。

But you should really understand database design, as you will see how to design your tables better, but for now make tables with as many fields you want as long as you respect some normalization rules 但是你应该真正理解数据库设计,因为你将看到如何更好地设计表,但是现在只要你尊重一些规范化规则就可以创建你想要的字段数。

I think you never want to change qour schema after your database was in use som for some time. 我想你永远不想在你的数据库使用som一段时间后改变qour架构。

Think about features/functions you propably could wanting to implement in feature, and decide basing on that, if you want to have 40 columns. 考虑一下您可能希望在功能中实现的功能/功能,并根据需要决定,如果您想要有40列。

I prefer to have everything as compact as possible, so i got a lot of foreign-keys and a lot of small tables for the reason to not write or have saved anything twice. 我更喜欢把所有东西都尽可能紧凑,所以我有很多外键和很多小桌子,因为没有写或两次保存任何东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 您是否应该使FK成为另一个表的索引? - Should you make FK the index of another table? 您是否应该将表计数存储在另一个表中? - Should you Store Table Count in another table? 如何计算表中的列数 - How do you count the number of columns in a table 复合主键的每个列都引用另一个表的主键。 该表的外键应该是什么? - Composite Primary Key's columns each refer to a Primary Key of another table. What should be the Foreign Keys for this table? 可以插入表的最大列数/值 - mysql - Maximum number of columns / values you can INSERT INTO a table - mysql MySQL:我应该使表中的所有列都建立索引吗? - MySQL: should I make all columns in my table indexed? 我应该制作另一个表还是只使用数组? (归一化或不归一化) - Should I make another table or just use arrays? (To normalize or not to normalize) 将多列连接到另一个表以从数字返回描述 - Join multiple columns to another table to return description from number 您如何相对于另一个表制作单元格值? - How do you make a cell value relative to another table? 如何将n个列添加到现有表中,新列应具有现有列的聚合 - How to add n number of columns to an existing table,the new columns should have the aggregate of an existing column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM