1:n或n:m,表关系

huangapple go评论172阅读模式
英文:

1:n or n:m, Table Relationship

问题

Sentence表和FollowUp表分别存储字符串句子和一些元数据列。

FollowUp表保存了哪些句子被其他句子跟进。因此,在我的FollowUp表中,我引用了两个句子ID(sentenceFrom,sentenceTo)。

我的问题是:这两个表之间的关系是1:n还是n:m?

我的解释如下:
Sentence表中的1行通常在FollowUp表中有两个引用(一个是sentenceTo,一个是sentenceFrom)。
FollowUp表中的1行也会引用多行Sentence表中的记录。

所以是n:m关系,但是在这两者之间我应该使用什么中间表呢?

英文:

I have two tables: Sentence and FollowUp.

Sentence simply stores string sentences and a few metadata columns.
FollowUp saves which sentences are followed up by certain other sentences. So, in my followUp table, I reference two sentenceIds (sentenceFrom, sentenceTo).

My question: Is the relationship between these two tables 1:n or n:m?

My explanation would be the following:
1 line out of Sentence has mostly two references in FollowUp (one sentenceTo, one sentenceFrom).
1 line out of FollowUp also references more than one line in Sentence.

So n:m right, but what intermediate-table should I use between those two?

答案1

得分: 0

这是一个n:m关系,但你不需要另一张表,因为参与关系的两个实体都是Sentence

换句话说,考虑到n:m关系需要一个中间表来记录配对关系,你的FollowUp表充当了这个中间表。

英文:

It is an n:m relationship, but you don't need another table, because both entities involved in the relationship are Sentence.

In other words, given that an n:m relationship needs an intermediate table to record the pairings, your FollowUp table serves as that intermediate table.

答案2

得分: 0

这是一个链表数据结构。因此可能存在一或两种关系。将会有:

  1. 句子 - 跟随 - 句子

  2. 句子 - 被句子跟随 (可选)

当同时存在这两种关系时,你拥有一个双向链表。

根据你的描述,这两者都是一对一关系,所以你实际上可以将它们放在“句子”表格上,例如:

句子 (数值, 元数据列1, ..., 元数据列N, 前一句子, 后一句子)

英文:

Data structure-wise this is a linked list. As such there can be one or two relationships. There would be:

  1. > Sentence - Follows - Sentence
  2. > Sentence - Is followed by - Sentence (Optional)

When you have both relationships you have a doubly linked list.

Based on your description these are both 1 - 1 relationships so you can actually just put them on the Sentence table e.g.

>Sentence (value, metadataColumn1, ..., metadataColumnN, previousSentence, nextSentence)

huangapple
  • 本文由 发表于 2020年1月7日 01:22:23
  • 转载请务必保留本文链接:https://go.coder-hub.com/59616364.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定