子类型或单独的表? [英] subtype or separate tables?

查看:66
本文介绍了子类型或单独的表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下实体:书籍、作者和商店.

I have the following entities: Books, Authors, and Stores.

他们每个人都可以有一个评论部分.我应该将评论存储在单独的表中还是有子类型/超类型设计?如果我使用单独的表格在技术上是错误的吗?因为无论哪种方式,它可能需要相同的工作量,或者如果任何子类型的超类型层次结构发生变化,子类型设计可能需要更多的工作.

Each of them can have a comments section. Should I store the comments in a separate table OR have a subtype/supertype design? Is it technically wrong if I use separate tables? Because either way, it may required the same amount of work OR the subtype design may require more work if a supertype hierarchy changes for any subtype.

推荐答案

超类型和子类型解决了这个问题这些东西并不完全相同,但也并非完全不同."

Supertypes and subtypes attack the issue "These things are not exactly alike, but they're also not utterly different."

超类型/子类型设计要求一些属性存储在超类型中,一些属性存储在子类型中.现实世界中每个事物的属性都分布在两个表中.

A supertype/subtype design requires that some attributes be stored in the supertype, and some be stored in the subtype. The attributes for each thing in the real world are split between two tables.

如何决定如何拆分属性?所有 子类型共有的属性向上"移动到超类型中.因此,如果您从公司和个人开始,他们并不完全相同,因为

How do you decide how to split up the attributes? The attributes common to all subtypes move "up" into the supertype. So if you were starting with companies and individuals, they're not exactly alike, because

  • 一个是个人,另一个是(概念上)一群人,
  • 一个可以有孩子,另一个不能,
  • 一个可以结婚,另一个不能

等等.

它们并没有完全不同,因为

They're not utterly different, because

  • 两者都可以有多个地址、电话号码、电子邮件地址、网站等,
  • 两者都可以与其他公司签订合同,
  • 两者都可以与其他人签订合同,
  • 两者都需要提交纳税申报表

等等.

两者共有的属性(至少是合法名称)向上"冒泡到超类型中.

The attributes common to both (legal name, at the very least) bubble "up" into the supertype.

不过,就您而言,尚不清楚书籍、作者和商店如何适应该分析.很明显,它们并不完全相同.但它们完全不同吗?我想是的.

In your case, though, it's not clear how books, authors, and stores fit into that analysis. It's clear that they're not exactly alike. But are they utterly different? I think so.

如果您谈论的是有关书籍、人物和商店的网站帖子之类的内容,那就另当别论了.对类似问题的回答包含代码.

If you're talking about something like web site posts about books, persons, and stores, that's a different story. The answer to a similar SO question includes code.

这篇关于子类型或单独的表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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