继承与数据库设计 [英] Inheritance & Database Design

查看:194
本文介绍了继承与数据库设计的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您通过数据库模型中的类表继承关系建模继承时,您是否...

When you model inheritance through class table inheritance relationships in a database model, do you...

1)包含一个属性两个子菜单的布尔值,更多子菜单的字符串),用于标识每个记录的特定子菜单?

1) Include an attribute (boolean for two subtipes, string for more subtipes) which identifies the particular subtipe of each record?

2)将此标识作为外键包含在包含描述所有可能的子类型?

2) Include this identification as a foreign key to a table containing a description of all the possible subtypes?

3)上述没有一个,依靠试错在几个子表中查找是否需要?

3) None of the above and rely on "trial and error" lookup in subtables on the few times it is needed?

推荐答案

我希望在大多数情况下,每个类层次结构模型的表,其中一列是一个歧视列解决方案)。如果您真的需要第二个表,因为需要许多子类型,那么也许您应该将表分解成几个表,因为我会怀疑很多数据将被调用,并且为null。

I would prefer in most cases the table per class hierarchy model, in which one column is a discriminator column (you 1. solution). If you really need the second table because of many subtypes that are needed, well perhaps you should break the tables into few tables, because I would suspect that much data will be reduntant, and null.

每个子类模型还有一个表,其中有一个具有共享数据的主表,子类的子表(数据完全标准化)虽然使用这种数据更困难,除非可能使用像NHibernate这样的ORM工具。

There is also a table per subclass model, in which you have a master table with shared data, and child tables for subclasses (data completly normalized) although working with this kind of data is harder, except when maybe using ORM tool like NHibernate.

你能否提供具体的解决情况的例子,因为在这些情况下,子类的数量通常在前面已知(如BillingDetails - > CreditCard,BankAccount等)

Could you provide the concrete example of situation you are solving, because in these cases the number of subclasses is usually known up-front (like BillingDetails -> CreditCard, BankAccount etc...)

这篇关于继承与数据库设计的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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