单表分层数据

发布于 2024-11-03 19:26:44 字数 172 浏览 1 评论 0原文

示例)构建一个具有如下层次结构的网站:区域 ->帮派->向导。

这些对象中的每一个都将具有非常接近相同的列(uid、胜利、损失、hp 等)。用户可以创建领地(不同类型的领地)、帮派和巫师。巫师可以是领土的直接子代。

将所有三个对象存储在一个表中是否有意义,并且根据地区类型使用不同的表?

Example) Building a site where there is a hierarchal structure like so: Territory -> Gang -> Wizard.

Each one of these objects will have very close to the same columns (uid, wins, losses, hp etc..). Users can create territories (different types of territories), gangs, and wizards. Wizards can be a direct child of territory.

Would it make sense to store all three objects in a single table with different tables based on the territory type?

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

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

发布评论

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

评论(2

终弃我 2024-11-10 19:26:44

不,(在我看来)这样做是没有意义的。它们是不同种类的东西,所以它们应该存储在不同的表中。

如果它们有某些共同点,那么您可以创建一个表来存储该方面以及与正确实体之间的适当外键关系。但它们主要是不同种类的东西,所以应该分开。

例如,一个领地不能包含其他领地,但可以包含帮派。因此,这些实体在重要方面是不同的,应该单独存储。

No, (in my opinion) it wouldn't make sense to do that. They are different kinds of things, so they should be stored in different tables.

If they have some aspect in common, then you could make a single table that stores that aspect with appropriate foreign key relationships to or from the correct entities. But they are mainly different kinds of things, so they should be separated.

For example, territories cannot contain other territories, though they can contain gangs. Therefore, the entities are dissimilar in important ways, and should be stored separately.

野侃 2024-11-10 19:26:44

这看起来像是一代规格设计模式的一个案例,此外由于它们之间的关系而以层次结构进行组织。

gen-spec 模式已被讨论过多次。 查看之前的讨论

一旦有了一个通用表,除了专用表之外,您还可以使用邻接列表方法或嵌套集方法对该表中的层次结构进行建模。在你的情况下,我会使用嵌套集。

This looks like a case of the gen-spec design pattern, in addition to being organized in a hierarchy because of their relationships to each other.

The gen-spec pattern has been discussed several times. See previous discussion.

Once you have a single generalized table, in addition to the specialized table, you can model the hierachy in that table, using either the adjacency list method, or the nested-set method. In your case, I would use nested set.

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