人与人之间的不同,人与人之间的不同

时间:2022-10-03 23:01:39

What is the real difference between one to many and many to one relationship? It is only reversed, kind of?

人与人之间的真正区别是什么?只是颠倒了,是不是?

I can't find any 'good-and-easy-to-understand' tutorial about this topic other than this one: SQL for Beginners: Part 3 - Database Relationships

除了这个主题之外,我找不到任何关于这个主题的“好且容易理解”教程:初学者SQL:第3部分——数据库关系

9 个解决方案

#1


82  

Yes, it a vice versa. It depends on which side of the relationship the entity is present on.

For example, if one department can employ for several employees then, department to employee is a one to many relationship (1 department employs many employees), while employee to department relationship is many to one (many employees work in one department).

是的,反之亦然。这取决于实体所处关系的哪一面。例如,如果一个部门可以雇佣数名员工,那么部门对员工来说是一个关系(1个部门雇佣了很多员工),而员工与部门之间的关系是很多的(很多员工在一个部门工作)。

More info on the relationship types:

更多关于关系类型的信息:

Database Relationships - IBM DB2 documentation

数据库关系——IBM DB2文档。

#2


25  

from http://www.sum-it.nl/cursus/dbdesign/english/intro030.php3

从http://www.sum-it.nl/cursus/dbdesign/english/intro030.php3

Most relations between tables are one-to-many.

表之间的大多数关系是一对多的。

Example:

例子:

* One area can be the habitat of many readers.
* One reader can have many subscriptions.
* One newspaper can have many subscriptions.

A Many to One relation is the same as one-to-many, but from a different viewpoint.

一个多对一个关系和一对多关系是一样的,但是从不同的观点来看。

* Many readers live in one area.
* Many subscriptions can be of one and the same reader.
* Many subscriptions are for one and the same newspaper.

#3


8  

What is the real difference between one to many and many to one relationship?

人与人之间的真正区别是什么?

There are conceptual differences between these terms that should help you visualize the data and also differences in the generated schema that should be fully understood. Mostly the difference is one of perspective though.

这些术语之间存在概念上的差异,这些差异应该有助于您可视化数据,并且生成的模式中的差异应该得到充分的理解。不过,主要的不同之处在于视角的不同。

In a one-to-many relationship, the local table has one row that may be associated with many rows in another table. In the example from SQL for beginners, one Customer may be associated to many Orders.

在一对多关系中,本地表有一行可能与另一个表中的许多行相关联。在SQL初学者的示例中,一个客户可能与多个订单相关联。

In the opposite many-to-one relationship, the local table may have many rows that are associated with one row in another table. In our example, many Orders may be associated to one Customer. This conceptual difference is important for mental representation.

在相反的多对一关系中,本地表可能有许多行,这些行与另一个表中的一行相关联。在我们的示例中,许多订单可能与一个客户相关联。这种观念上的差异对心理表征很重要。

In addition, the schema which supports the relationship is represented differently in the Customer and Order tables. If the customer has columns id and name:

此外,支持关系的模式在Customer和Order表中有不同的表示。如果客户有列id和名称:

id,name
1,Bill Smith
2,Jim Kenshaw

Then for a Customer to be associated with Orders, many SQL implementations add to the Order table a column which stores the id of the associated Customer (in this schema customer_id:

然后,对于要与订单相关联的客户,许多SQL实现会向Order表添加一个列,该列存储关联客户的id(在这个模式customer_id中:

id,date,amount,customer_id
10,20160620,12.34,1
11,20160620,7.58,1
12,20160621,158.01,2

In the above data rows, if we look at the customer_id id column, we see that Bill Smith (customer-id #1) has 2 orders associated with him: one for $12.34 and one for $7.58. Jim Kenshaw (customer-id #2) has only 1 order for $158.01.

在上面的数据行中,如果我们查看customer_id列,我们会看到Bill Smith(客户id #1)有两个与他相关的订单:一个是12.34美元,另一个是7.58美元。吉姆·肯肖(客户id #2)只有一份158.01美元的订单。

What is important to realize is that typically the one-to-many relationship doesn't actually add any columns to the table that is the "one". The Customer has no extra columns which describe the relationship with Order. In fact the Customer might also have a one-to-many relationship with ShippingAddress and SalesCall tables and yet have no additional columns added to the Customer table.

需要注意的是,一对多关系通常不会向“1”表添加任何列。客户没有额外的列来描述与订单的关系。事实上,客户也可能与ShippingAddress和SalesCall表有一对多的关系,但是没有向客户表添加额外的列。

However, for a many-to-one relationship to be described, often an id column is added to the many table which is a foreign-key to the one table -- in this case a customer_id column is added to the Order. To associated order #10 for $12.34 to Bill Smith, we assign the customer_id column to Bill Smith's id 1.

然而,对于要描述的多对一关系,通常会将id列添加到多表中,而多表是一个表的外键——在本例中,customer_id列被添加到订单中。我们将customer_id列分配给Bill Smith的id 1,以获得12.34美元的相关订单#10。

Hope this helps.

希望这个有帮助。

#4


6  

Answer to your first question is : both are similar,

回答你的第一个问题是:两者都是相似的,

Answer to your second question is: one-to-many --> a MAN(MAN table) may have more than one wife(WOMEN table) many-to-one --> more than one women have married one MAN.

回答你的第二个问题是:一对多——一个男人(男人桌)可能有不止一个妻子(女人桌)多对一个——比一个女人嫁了一个男人还多。

Now if you want to relate this relation with two tables MAN and WOMEN, one MAN table row may have many relations with rows in the WOMEN table. hope it clear.

如果你想把这个关系与两个表MAN和woman联系起来,一个MAN表行可能与WOMEN表中的行有很多关系。希望它清楚。

#5


3  

There is no difference. It's just a matter of language and preference as to which way round you state the relationship.

没有区别。这只是语言和偏好的问题,你如何描述这种关系。

#6


2  

One-to-Many and Many-to-One are similar in Multiplicity but not Aspect (i.e. Directionality).

一对多和多对一在多重性方面是相似的,但不是方面(即方向性)。

The mapping of Associations between entity classes and the Relationships between tables. There are two categories of Relationships:

实体类之间的关联映射和表之间的关系。有两种关系:

  1. Multiplicity (ER term: cardinality)
    • One-to-one relationships: Example Husband and Wife
    • 一对一的关系:例如丈夫和妻子
    • One-to-Many relationships: Example Mother and Children
    • 一对多关系:例如母亲和孩子
    • Many-to-Many relationships: Example Student and Subject
    • 多对多关系:学生和主题的例子
  2. 多重性(ER项:基数)一对一关系:例如夫妻关系:例如母亲和孩子多对多关系:例如学生和主题。
  3. Directionality : Not affect on mapping but makes difference on how we can access data.
    • Uni-directional relationships: A relationship field or property that refers to the other entity.
    • 单向关系:指其他实体的关系字段或属性。
    • Bi-directional relationships: Each entity has a relationship field or property that refers to the other entity.
    • 双向关系:每个实体都有一个关系字段或属性来引用另一个实体。
  4. 方向性:不影响映射,但影响我们访问数据的方式。单向关系:指其他实体的关系字段或属性。双向关系:每个实体都有一个关系字段或属性来引用另一个实体。

#7


0  

  • ---One to Many--- A Parents can has two or more children.
  • ---对许多人来说---父母可以有两个或更多的孩子。
  • ---Many to one--- Those 3 children can have a single Parents.

    --- --- --- --- --- --- --- --- --- --- ---这3个孩子可以有一个单亲家庭。

    Both are similar. This can be used belongs to the need. If you wanna find children for a particular parents, then u can go with One-To-Many. or else, wanna find parents for a twins, you may go with Many-To-One. Likewise....,

    都是相似的。这是属于需要的。如果你想为特定的父母找到孩子,你可以用一对多。或者,如果你想为双胞胎找到父母,你可以选择多对一。同样....,

#8


-1  

There's no practical difference. Just use the relationship which makes the most sense given the way you see your problem as Devendra illustrated.

没有实际的区别。只要使用这种关系,就像Devendra所阐述的那样,你会发现自己的问题。

#9


-7  

one-to-many has parent class contains n number of childrens so it is a collection mapping. mant-to-one has n number of childrens contains one parent so it is a object mapping

一对多的父类包含n个子类,所以它是一个集合映射。man -to- 1有n个子代包含一个父类,所以它是一个对象映射

#1


82  

Yes, it a vice versa. It depends on which side of the relationship the entity is present on.

For example, if one department can employ for several employees then, department to employee is a one to many relationship (1 department employs many employees), while employee to department relationship is many to one (many employees work in one department).

是的,反之亦然。这取决于实体所处关系的哪一面。例如,如果一个部门可以雇佣数名员工,那么部门对员工来说是一个关系(1个部门雇佣了很多员工),而员工与部门之间的关系是很多的(很多员工在一个部门工作)。

More info on the relationship types:

更多关于关系类型的信息:

Database Relationships - IBM DB2 documentation

数据库关系——IBM DB2文档。

#2


25  

from http://www.sum-it.nl/cursus/dbdesign/english/intro030.php3

从http://www.sum-it.nl/cursus/dbdesign/english/intro030.php3

Most relations between tables are one-to-many.

表之间的大多数关系是一对多的。

Example:

例子:

* One area can be the habitat of many readers.
* One reader can have many subscriptions.
* One newspaper can have many subscriptions.

A Many to One relation is the same as one-to-many, but from a different viewpoint.

一个多对一个关系和一对多关系是一样的,但是从不同的观点来看。

* Many readers live in one area.
* Many subscriptions can be of one and the same reader.
* Many subscriptions are for one and the same newspaper.

#3


8  

What is the real difference between one to many and many to one relationship?

人与人之间的真正区别是什么?

There are conceptual differences between these terms that should help you visualize the data and also differences in the generated schema that should be fully understood. Mostly the difference is one of perspective though.

这些术语之间存在概念上的差异,这些差异应该有助于您可视化数据,并且生成的模式中的差异应该得到充分的理解。不过,主要的不同之处在于视角的不同。

In a one-to-many relationship, the local table has one row that may be associated with many rows in another table. In the example from SQL for beginners, one Customer may be associated to many Orders.

在一对多关系中,本地表有一行可能与另一个表中的许多行相关联。在SQL初学者的示例中,一个客户可能与多个订单相关联。

In the opposite many-to-one relationship, the local table may have many rows that are associated with one row in another table. In our example, many Orders may be associated to one Customer. This conceptual difference is important for mental representation.

在相反的多对一关系中,本地表可能有许多行,这些行与另一个表中的一行相关联。在我们的示例中,许多订单可能与一个客户相关联。这种观念上的差异对心理表征很重要。

In addition, the schema which supports the relationship is represented differently in the Customer and Order tables. If the customer has columns id and name:

此外,支持关系的模式在Customer和Order表中有不同的表示。如果客户有列id和名称:

id,name
1,Bill Smith
2,Jim Kenshaw

Then for a Customer to be associated with Orders, many SQL implementations add to the Order table a column which stores the id of the associated Customer (in this schema customer_id:

然后,对于要与订单相关联的客户,许多SQL实现会向Order表添加一个列,该列存储关联客户的id(在这个模式customer_id中:

id,date,amount,customer_id
10,20160620,12.34,1
11,20160620,7.58,1
12,20160621,158.01,2

In the above data rows, if we look at the customer_id id column, we see that Bill Smith (customer-id #1) has 2 orders associated with him: one for $12.34 and one for $7.58. Jim Kenshaw (customer-id #2) has only 1 order for $158.01.

在上面的数据行中,如果我们查看customer_id列,我们会看到Bill Smith(客户id #1)有两个与他相关的订单:一个是12.34美元,另一个是7.58美元。吉姆·肯肖(客户id #2)只有一份158.01美元的订单。

What is important to realize is that typically the one-to-many relationship doesn't actually add any columns to the table that is the "one". The Customer has no extra columns which describe the relationship with Order. In fact the Customer might also have a one-to-many relationship with ShippingAddress and SalesCall tables and yet have no additional columns added to the Customer table.

需要注意的是,一对多关系通常不会向“1”表添加任何列。客户没有额外的列来描述与订单的关系。事实上,客户也可能与ShippingAddress和SalesCall表有一对多的关系,但是没有向客户表添加额外的列。

However, for a many-to-one relationship to be described, often an id column is added to the many table which is a foreign-key to the one table -- in this case a customer_id column is added to the Order. To associated order #10 for $12.34 to Bill Smith, we assign the customer_id column to Bill Smith's id 1.

然而,对于要描述的多对一关系,通常会将id列添加到多表中,而多表是一个表的外键——在本例中,customer_id列被添加到订单中。我们将customer_id列分配给Bill Smith的id 1,以获得12.34美元的相关订单#10。

Hope this helps.

希望这个有帮助。

#4


6  

Answer to your first question is : both are similar,

回答你的第一个问题是:两者都是相似的,

Answer to your second question is: one-to-many --> a MAN(MAN table) may have more than one wife(WOMEN table) many-to-one --> more than one women have married one MAN.

回答你的第二个问题是:一对多——一个男人(男人桌)可能有不止一个妻子(女人桌)多对一个——比一个女人嫁了一个男人还多。

Now if you want to relate this relation with two tables MAN and WOMEN, one MAN table row may have many relations with rows in the WOMEN table. hope it clear.

如果你想把这个关系与两个表MAN和woman联系起来,一个MAN表行可能与WOMEN表中的行有很多关系。希望它清楚。

#5


3  

There is no difference. It's just a matter of language and preference as to which way round you state the relationship.

没有区别。这只是语言和偏好的问题,你如何描述这种关系。

#6


2  

One-to-Many and Many-to-One are similar in Multiplicity but not Aspect (i.e. Directionality).

一对多和多对一在多重性方面是相似的,但不是方面(即方向性)。

The mapping of Associations between entity classes and the Relationships between tables. There are two categories of Relationships:

实体类之间的关联映射和表之间的关系。有两种关系:

  1. Multiplicity (ER term: cardinality)
    • One-to-one relationships: Example Husband and Wife
    • 一对一的关系:例如丈夫和妻子
    • One-to-Many relationships: Example Mother and Children
    • 一对多关系:例如母亲和孩子
    • Many-to-Many relationships: Example Student and Subject
    • 多对多关系:学生和主题的例子
  2. 多重性(ER项:基数)一对一关系:例如夫妻关系:例如母亲和孩子多对多关系:例如学生和主题。
  3. Directionality : Not affect on mapping but makes difference on how we can access data.
    • Uni-directional relationships: A relationship field or property that refers to the other entity.
    • 单向关系:指其他实体的关系字段或属性。
    • Bi-directional relationships: Each entity has a relationship field or property that refers to the other entity.
    • 双向关系:每个实体都有一个关系字段或属性来引用另一个实体。
  4. 方向性:不影响映射,但影响我们访问数据的方式。单向关系:指其他实体的关系字段或属性。双向关系:每个实体都有一个关系字段或属性来引用另一个实体。

#7


0  

  • ---One to Many--- A Parents can has two or more children.
  • ---对许多人来说---父母可以有两个或更多的孩子。
  • ---Many to one--- Those 3 children can have a single Parents.

    --- --- --- --- --- --- --- --- --- --- ---这3个孩子可以有一个单亲家庭。

    Both are similar. This can be used belongs to the need. If you wanna find children for a particular parents, then u can go with One-To-Many. or else, wanna find parents for a twins, you may go with Many-To-One. Likewise....,

    都是相似的。这是属于需要的。如果你想为特定的父母找到孩子,你可以用一对多。或者,如果你想为双胞胎找到父母,你可以选择多对一。同样....,

#8


-1  

There's no practical difference. Just use the relationship which makes the most sense given the way you see your problem as Devendra illustrated.

没有实际的区别。只要使用这种关系,就像Devendra所阐述的那样,你会发现自己的问题。

#9


-7  

one-to-many has parent class contains n number of childrens so it is a collection mapping. mant-to-one has n number of childrens contains one parent so it is a object mapping

一对多的父类包含n个子类,所以它是一个集合映射。man -to- 1有n个子代包含一个父类,所以它是一个对象映射