database ER图中的一对多关系

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15896699/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 08:56:03  来源:igfitidea点击:

One-to many relationships in ER diagram

databaserelational-databaseentity-relationship

提问by yrazlik

I am trying to show the following in the ER diagram:

我试图在 ER 图中显示以下内容:

There are instructors and courses, a course is taught by only one instructor
whereas an instructor can give many courses.

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

My question is, is there any difference between two diagrams, in other words, does it matter which line we turn into an arrow, or what only matters is only the direction of the arrow?

我的问题是,两个图表之间有什么区别,换句话说,我们把哪条线变成箭头重要,还是只重要箭头的方向?

Also, if we think about the mapping cardinalities; is it 1 to many or many to 1? If we think in terms of courses, then it is many to one but if we think in terms of instructors, then it is one to many. How do we decide this? Thank you.

另外,如果我们考虑映射基数;是1比多还是多比1?如果我们从课程的角度考虑,那么它是多对一的,但是如果我们从教师的角度考虑,那么它就是一对多的。我们如何决定这一点?谢谢你。

回答by Dulantha

In ER diagrams when the relationship is denoted the arrows are not used. Some instructors use this arrow when they want to decide the cardinalities but that is just to get the cardinality (1:1, 1:M and N:M)

在 ER 图中,当表示关系时,不使用箭头。一些教师在想要决定基数时会使用此箭头,但这只是为了获得基数(1:1、1:M 和 N:M)

I have attached the ER diagram for this in Chen notation and also using Crow Notation you can use either of them.

我在 Chen 符号中为此附上了 ER 图,并且使用 Crow Notation 你可以使用它们中的任何一个。

ER Digram

ER图

Deciding the cardinality for a relationship is a practical scenario there is no hard and pass rule to obtain it. What you need to do is start from one side of the relationship and take one tuple (instance) and see how many tuples from the other entity participate for the relationship. Then do the vise versa. Then you know the participation number of tuples) from each entity to the relationship. Think about set theory and functions in mathematics when you decide the cardinality (ie Set of instructors, Set of Courses and set of Teaches relationship type) then this is so easy but if you are not from a mathematic background just think of practical scenario.

确定关系的基数是一个实际场景,没有硬性规则来获得它。你需要做的是从关系的一侧开始,取一个元组(实例),看看有多少来自另一个实体的元组参与了关系。然后反之亦然。然后你知道从每个实体到关系的元组的参与数。当您决定基数时,请考虑数学中的集合论和函数(即教师集、课程集和教学关系类型),那么这很容易,但如果您不是数学背景,请考虑实际场景。

For Example

例如

a) For 1 instructor he or she can teach Many (M) courses

a) 对于 1 个讲师,他或她可以教授许多 (M) 门课程

b) For 1 Course there is only 1 instructor

b) 对于 1 门课程,只有 1 名讲师

so in instructor side there is always 1 in a) and b) but in Courses there is M and 1 in a) and b) there for Instructor:Course cardinality is 1:M

因此,在讲师方面,a) 和 b) 中始终为 1,但在课程中,a) 和 b) 中存在 M 和 1,其中 Instructor:Course 基数为 1:M

回答by debater

I don't think the other answer is fully correct.

我不认为另一个答案是完全正确的。

I would say that one shoulduse arrows, and one should use a notation that gives a meaningful name to each directionof the relationship. In this case it will be "teaches" in one direction, and "is taught by" in the other. Either use arrows next to the names or put the name near to the entity to which it refers. You could use one line (with two arrow heads) or two lines (with one arrow each).

我会说应该使用箭头,并且应该使用一种符号,为关系的每个方向提供一个有意义的名称。在这种情况下,它将在一个方向上“教”,而在另一个方向上“教”。要么在名称旁边使用箭头,要么将名称放在它所指的实体附近。您可以使用一条线(带有两个箭头)或两条线(每条带有一个箭头)。

I would also suggest that cardinality is just one kind of constraint, and the notation should reflect that. For example, the two names for the relationship could be "teaches (many)" and "is taught by (exactly one)". The point is you might have "teaches (one or two)" or "is taught by (exactly two)" and so on.

我还建议基数只是一种约束,符号应该反映这一点。例如,关系的两个名称可以是“teaches (many)”和“istead by (exactly one)”。关键是你可能有“教(一两个)”或“由(正好两个)教”等等。

It is better to be explicit and clear about exactly what your constraints really are.

最好明确明确你的约束到底是什么。

回答by Yogendra

Both are having exactly opposite cardinality

两者都具有完全相反的基数

Simple clean line means many.

简单干净的线条意味着很多。

Arrow means one.

箭头表示一。

If we consider both with same cardinality.

如果我们考虑两者具有相同的基数。

then, many to many should be represented by following the second convention as (please assume diamond for relationship set and rectangle for entity set)

那么,多对多应该按照第二个约定表示为(请假设关系集为菱形,实体集为矩形)

   INSTRUCTOR <---- TEACHES -----> COURSE 

which is actually of no meaning.

这实际上没有任何意义。

If we consider both with opposite cardinality.

如果我们考虑两者的基数相反。

then, many to many should be represented by following the second convention as (please assume diamond for relationship set and rectangle for entity set)

那么,多对多应该按照第二个约定表示为(请假设关系集为菱形,实体集为矩形)

  INSTRUCTOR ----- TEACHES ------ COURSE

No explicit arrow is always considered many to many. So, it is correct (only if we consider both opposite)

没有明确的箭头总是被认为是多对多的。所以,这是正确的(仅当我们考虑两者相反时)

回答by Naveesh Kumar V

Consider an 'employee' entity set and 'department' entity set, having relationship set as 'manage'. Employee-------------Manage--------------------Department (entity set) (Relationship set) (entity set) One to many relationship means one entity of employee set can be associated with more than one entity of Department entity set but, an entity of Department set can be associated with at most one entity of employee entity set. That means if there is one to many relationship between employee and department entity sets, then each employee can manage more than one department and at the same time each department is managed by at most one employer.

考虑一个“员工”实体集和“部门”实体集,将关系设置为“管理”。Employee------------管理--------------------部门(实体集)(关系集)(实体集)一到多关系意味着一个员工集合实体可以关联多个部门实体集合实体,但是一个部门集合实体最多可以关联一个员工实体集合实体。这意味着如果雇员和部门实体集之间存在一对多的关系,那么每个雇员可以管理多个部门,同时每个部门最多由一个雇主管理。