如何在RDBMS中表示对象分类层次结构 [英] How do I represent object classification hierarchy in a RDBMS

查看:117
本文介绍了如何在RDBMS中表示对象分类层次结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的数据 IF 将由对象表示,如下所示:

My data, IF it would be represented by objects, it would look like:

abstract class A{
   int a;
   int b;
   string c;
}

class B inherits A{
  string D;
}

class C inherits A{
  int e;
  int f;
}

我的问题:我为实体B和C创建一个单独的表,
或者我创建一个主表,对于每个实体类型,我做不同的连接以获取数据。

在现实世界中,我将为所有实体提供大约15个类似的字段,关于1-3每个实体的唯一字段。

我期望最多100K条记录。

My question: Do I create a separate table for entities B and C, Or do I create one main table, and for each entity type I do different joins to fetch the data.
In the real world, I will have around 15 similar fields for all entities, and about 1-3 unique field for each entity.
I expect a max of 100K records.

任何见解?

推荐答案

你会发现关于这个话题的意见。许多人倡导具体表继承,其中(如您在第一个选项中所述)定义数据显示在每个表格中。

You'll find no shortage of opinions on this topic. Many people advocate concrete table inheritance, where (as you describe in your first option) you define the data explicitly in each table.

鉴于您的第二个声明,我将推荐此模式。我会想到有一个主表代表你的父母和辅助表代表孩子。您可能希望在主表中包含某种类型的标识符,以指示它是什么样的实体,但这可能是也可能不是必需的。至少,你需要像...一样的东西。

Given your second statement, I would not recommend this pattern. I would go with the idea of having a "main" table representing your parent and auxiliary tables representing the children. You may want to include a type identifier of some kind in your main table in order to indicate what sort of entity it is, but this may or may not be necessary. At a minimum, you need something like...

tableA
(
    ID (primary),
    A,
    B,
    C
)

tableB
(
    ID (primary and foreign->table_A),
    D
)

tableC
(
    ID (primary and foreign->table_A),
    E,
    F
)

这篇关于如何在RDBMS中表示对象分类层次结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆