简体   繁体   English

sql中的一对多标识关系

[英]one-to-many identifying relationship in sql

I have a big challenge that i am facing right now. 我现在面临着一个巨大的挑战。 I am designing a database when i have a strong entity "CLIENT" with a weak entity "AFFILIATE" which has the primary key of itself combined with the parent's primary key.The identifying relationship between the two must be a "ONE-TO-MANY" relationship and have the total participation. 当我有一个强实体“ CLIENT”和一个弱实体“ AFFILIATE”时,我正在设计一个数据库,该实体的主键与父级的主键结合在一起。两者之间的标识关系必须是“一对多”并拥有总参与度。 But my problem is that in SQL, as the primary key of the AFFILIATE must be defined by its discriminator and the parent's primary key, the one to many relationship will be inefficient as for example it will be possible in AFFILIATE to have one id_affiliate related to many id_client. 但是我的问题是,在SQL中,由于必须由AFFILIATE的鉴别符和父级的主键定义AFFILIATE的主键,所以一对多关系会效率低下,例如,在AFFILIATE中可能有一个id_affiliate与许多id_client。 Please help me. 请帮我。

This is not an unusual set up at all, do you have any specific cause to believe it will be inefficient? 这根本不是一个不寻常的设置,您是否有任何特定原因认为它效率低下?

Client should have a clustered primary key of id_client Affiliate should have a clustered primary key of id_client + id_affiliate 客户端应具有id_client的集群主键会员应具有id_client + id_affiliate的集群主键

The join between the two is a simple b-tree lookup without an additional hop for page lookup (because of the clustering key), and all of the affiliates for a given client are likely to be on the same data page, so the lookup will be very fast. 两者之间的连接是一个简单的b树查找,而没有用于页面查找的额外跃点(由于集群键的原因),并且给定客户端的所有会员都可能在同一数据页面上,因此查找将很快

I believe you are mistaken the complexity of weak and strong entity relationship. 我相信您误解了实体关系薄弱和关系牢固的复杂性。 In fact, in practice this concept has very little to no relevance when designing tables. 实际上,实际上,在设计表时,此概念几乎没有关联。 What you need to focus on is the cornerstone relationship between the two tables as part of your normalization process. 您需要关注的是标准化过程中两个表之间的基石关系。

Your details are a bit sketchy, but if you think that it will be inefficient because you will have multiple records returned when you query AFFILIATE looking for client id's, I would beg to differ. 您的详细信息有点粗略,但是如果您认为效率不高,因为在查询AFFILIATE来查找客户端ID时将返回多个记录,那么我想请您有所不同。

If this relationship is mandatory, you will not suffer any inefficiencies, if this is an optional relationship then in the context of relational database model there is no significant difference in your strong vs weak entity relationship. 如果此关系是强制性的,那么您将不会遭受任何低效率的影响,如果这是可选关系,则在关系数据库模型的上下文中,强实体关系与弱实体关系之间没有显着差异。

In fact, in your question, you answer your own question stating: 实际上,在您的问题中,您回答自己的问题,指出:

But my problem is that in SQL, as the primary key of the AFFILIATE must be defined by its discriminator and the parent's primary key, the one to many relationship will be inefficient as for example it will be possible in AFFILIATE to have one id_affiliate related to many id_client. 但是我的问题是,在SQL中,由于必须由AFFILIATE的鉴别符和父级的主键定义AFFILIATE的主键,所以一对多关系会效率低下,例如,在AFFILIATE中可能有一个id_affiliate与许多id_client。

This is not a problem, this is how it works. 这不是问题,这就是它的工作方式。

@John Wu and @Hituptony, thank you a lot for helping and the problem i had is now resolved. @John Wu和@Hituptony,非常感谢您的帮助,我遇到的问题现在已经解决。 In fact, i did not understand very well the concept of "Weak Entity set" where we can have weak entities with same discriminator but representing different objects as there are related to different strong entities. 实际上,我对“弱实体集”的概念不是很了解,在该概念中,我们可以拥有带有相同区分符但代表不同对象的弱实体,因为它们与不同的强实体相关。 For example, we can have same affiliate_id's but representing different affiliates of different clients. 例如,我们可以有相同的affiliate_id,但代表不同客户的不同会员。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM