样式问题 - 包含多个字段的数据库表
我正在开始一个新项目,我必须解析文档并将其存储在数据库中。本文档包含几个简单键值对部分 - 大约 10 个部分,总共大约 100 对。我可以每个部分有一个表,它们都一对一地映射到一个聚合。或者我可以有一张包含大约 100 个字段的表。我陷入困境,因为我不想制作那么大的单个表,但我也不想制作那么多的一对一映射。那么,我是做一张大桌子,还是做一堆小桌子呢?实际上,据我所知,实际上并没有什么区别。如果有请告诉我。
编辑 需要一个例子,所以我将提供一些可能有帮助的东西。
Document
- Section Title 1
- k1: val1
- k2: val2
...
- Section Title 2
- k10: val10
...
...
- Section Title n
- kn-1: valn-1
- kn: valn
而且我必须使用关系数据库,所以不必费心提出其他建议。
I'm starting a new project where I have to parse a document and store it in a database. This document contains several sections of simple key-value pairs - about 10 sections and about 100 pairs in total. I could have one table per section, and they all map one-to-one to an aggregate. Or I could have one table with about 100 fields. I'm stuck because I don't want to make a single table that big, but I also don't want to make that many one-to-one mappings either. So, do I make the big table, or do I make a bunch of smaller tables? Effectively, there wouldn't really be a difference as far as I can tell. If there are, please inform me.
EDIT
An example is desired so I will provide something that might help.
Document
- Section Title 1
- k1: val1
- k2: val2
...
- Section Title 2
- k10: val10
...
...
- Section Title n
- kn-1: valn-1
- kn: valn
And I have to use a relational database so don't bother suggesting otherwise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您有很多很多这个大文档的实例要存储(现在和/或随着时间的推移),并且如果此文档的每个实例将都有这 100 多个列的值,并且如果您想要在 RDBMS 中存储所有行和列的数据所固有的强大功能和灵活性,然后我将其全部存储为一个大(尽管丑陋)表。
如果给定部分中的所有“项目”总是被填充,但个别部分可能会或可能不会被填充,那么每个部分有一个表可能是有价值的......但听起来情况并非如此。
请警惕上面的“如果”。如果其中任何一个太不稳定,那么大表的想法可能会比它的价值更痛苦,而替代的想法(例如@9000的NoSQL想法)可能会更好。
If you have many, many instances of this big document to store (now and/or over time), and if each instance of this document will have values for those 100+ columns, and if you want the power and flexibility inherent in storing all that data actross rows and columns within an RDBMS, then I'd store it all as one big (albeit ugly) table.
If all the "items" in a given section are always filled, but invididual sections may or may not be filled, then there might be value in having one table per section... but it doesn't sound like this is the case.
Be wary of thise "ifs" above. If any of them are too shaky, then the big table idea may be more pain than it's worth, and alternate ideas (such as @9000's NoSQL idea) might be better.
如果数据仅用于只读目的,并且您的 xml 不要求您进行数据库方案更改(更改),那么我认为对单个表进行反规范化不会出现任何问题。另一种选择可能是查看EAV 模型
If the data is just for read-only purpose and your xml doesn't mandate you to make DB scheme changes (alters) then I doesn't see any problem de-normalizing to a single table. The other alternative might be to look at EAV models
是的,每个文档有 100 行名称/值对。但是,您可以轻松添加名称和值,而无需修改数据库。
Yes, you have 100's of rows of name/value pairs per document. However, you can easily add names and values without having to revise the database.