简体   繁体   中英

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. 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. 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

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.

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.

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.

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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