数据库中的一对一关系和一对多关系之间的差异 [英] Difference between one-to-one and one-to-many relationship in database

查看:380
本文介绍了数据库中的一对一关系和一对多关系之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能是一个基本的(愚蠢的)问题,但是当在数据库中具有一对一的关系时,另一个表有一个外键ID(在这个例子中)。在一对多关系中,表包含许多外键。

This is probably a basic(dumb) question but when having a one-to-one relationship in a database the other table has a foreign key ID(in this example). And in a one-to-many relationship the table contains many foreign keys.

但是数据库不知道这是一对一还是一对多的关系呢?我在ER-Diagram中所做的关系只是表示在制作实际表格时应该是外键的位置?

But the database does not know whether this is a one-to-one or one-to-many relationship right? The relationships that I make in an ER-Diagram is only to indicate where it should be foreign keys when making the actual tables?

我不完全理解

提前感谢。

推荐答案

在某种意义上,我们谈论的所有关系都不是已知的数据库,它们是我们发明的结构,以更好地了解如何设计表。

In a sense, all the relationships we talk about are not known to the database, they are constructs we have invented to better understand how to design the tables.

在一对一和一对多之间的表结构方面的巨大区别在于,在一对一中,有可能(但不必要)具有双向关系,意思表A可以有一个外键进入表B,并且表B可以有一个外键进入表A中的相关记录。这是一个一对多关系不可能的。

The big difference in terms of table structure between one-to-one and one-to-many is that in one-to-one it is possible (but not necessary) to have a bidirectional relationship, meaning table A can have a foreign key into table B, and table B can have a foreign key into the associated record in table A. This is not possible with a one-to-many relationship.

一对一关系将一个表中的一个记录与另一个表中的单个记录相关联。一对多关系将一个表中的一个记录与另一个表中的许多记录相关联。

One-to-one relationships associate one record in one table with a single record in the other table. One-to-many relationships associate one record in one table with many records in the other table.

这篇关于数据库中的一对一关系和一对多关系之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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