MySQL 如何在关系数据库中进行继承建模?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1567935/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to do Inheritance Modeling in Relational Databases?
提问by Rachel
My question is regarding Inheritance modeling in Relational Database Systems. I have canonical data model and in that I have some fields related to pricing of product inheriting certain attributes from product table and I want to model this inheritance in MySQL relational database and so,
我的问题是关于关系数据库系统中的继承建模。我有规范的数据模型,并且我有一些与从产品表继承某些属性的产品定价相关的字段,我想在 MySQL 关系数据库中对这种继承进行建模,因此,
"How can we do Inheritance Modeling in Relational Databases ?"
“我们如何在关系数据库中进行继承建模?”
Thanks.
谢谢。
回答by RichardOD
Martin Fowler discusses this extensively in his book Patterns of Enterprise Application Architecture book. Get this book and look into:
Martin Fowler 在他的《企业应用程序架构模式》一书中广泛讨论了这一点。获取这本书并查看:
The Website should give you some idea. You might also want to read the section on inheritance mappers. Each of the different approaches have their pros and cons so choose wisely.
该网站应该给你一些想法。您可能还想阅读有关继承映射器的部分。每种不同的方法都有其优点和缺点,因此请明智地选择。
回答by Todd Stout
回答by ChssPly76
Relational databases don't deal with objects (and, thus, inheritance) - they deal with relationships. What you're really asking is how to map your object structure to your database - and the answer to that is "it depends on your ORM layer".
关系数据库不处理对象(以及继承)——它们处理关系。您真正要问的是如何将对象结构映射到数据库 - 答案是“这取决于您的 ORM 层”。
Take a look at Mapping Objects to Relational Databases: O/R Mapping In Detailarticle for some details. If you tell us what software stack you're using, you'll likely get a more to-the-point answer.
有关详细信息,请查看Mapping Objects to Relational Databases: O/R Mapping In Detail文章。如果您告诉我们您使用的是什么软件堆栈,您可能会得到更中肯的答案。
回答by Walter Mitty
If you just want to look at some web articles instead of reading a book, you can find some good articles by Googling on:
如果你只想看一些网络文章而不是看书,你可以通过谷歌搜索找到一些不错的文章:
Generalization Specialization Relational Modeling
The gen-spec pattern covers a lot of the same ground that inheritance does in OOP environments.
gen-spec 模式涵盖了很多与 OOP 环境中的继承相同的基础。
If you google on
如果你谷歌
Generalization Specialization Object Modeling
you'll get a whole new batch of articles, most of which mention inheritance explicitly.
你会得到一批全新的文章,其中大部分都明确提到了继承。
There is a design technique that's summarized in the following tag class-table-inheritanceunder the info tag. This allows you to use subclass tables to "extend" a class table, if you'll allow a strange use of the word "extend". There's some work involved, but it's worth it.
在 info 标签下的以下标签class-table-inheritance 中总结了一种设计技术。这允许您使用子类表来“扩展”类表,如果您允许奇怪地使用“扩展”一词。需要做一些工作,但这是值得的。
回答by Erwin Smout
Chapter 6 of "Practical Issues in Database Management" is probably an interesting read for you.
“数据库管理中的实际问题”的第 6 章对您来说可能很有趣。
As are all the other chapters, probably, but those don't relate directly to your question.
可能与所有其他章节一样,但这些章节与您的问题没有直接关系。