UML ERD数据库建模查询

huangapple go评论64阅读模式
英文:

UML ERD Database modelling Query

问题

I have the following tables in my database.

  1. (Member) is assigned to 1.m facility
  2. (Facility) has assigned 1.m member
  3. (Facility) enrolled to 1.m program
  4. (Program) enrolls 1.m facility

I want to query all member facilities that are not enrolled in a program.

Should there be a direct link between (nacmemberfacility) and (nacFacilityProgram)?

Can two intersecting entities be linked?

What is code for this query?

英文:

I have the following tables in my database.

  1. (Member) is assigned to 1.m facility
  2. (Facility) has assigned 1.m member
  3. (Facility) enrolled to 1.m program
  4. (Program) enrolls 1.m facility

I want to query all member facilities that are not enrolled in a program.

Should there be a direct link between (nacmemberfacility) and (nacFacilityProgram)?

Can two intersecting entities be linked?

What is code for this query?

UML ERD数据库建模查询

答案1

得分: -1

Member - Facility 是根据您的叙述一个多对多的关系。在您的图表中,您将其分解为两个一对多的关系 Member - MemberFacility - Facility(在这方面图表是错误的)。请注意,在这两种情况下,“多”的一侧都在错误的一侧。

对于 Facility - Program 也是一样,您将其转化为了 Facility - FacilityProgram - Program

如果您想找出所有未参加 ProgramMemberFacility,则无需直接关系连接 MemberFacilityProgram,因为您可以从现有的关系中推断出:

select * from MemberFacility 
   where facilityId not in (select facilityId from MemberProgram); 

只有在设施的个别成员是否参加设施所参加的计划时,您才需要直接关系。

英文:

Member - Facility is a many-to-many relationship according to your narrative. In your diagram you have decomposed it into two one-to-many relationships Member - MemberFacility - Facility (the diagram is wrong in this regard). Note that the "many" side is on the wrong side in both cases.

Same for Facility - Program which you transformed into Facility - FacilityProgram - Program

If you want to find out all the MemberFacility that are not enrolled in a Program, you do not need a direct relationship between MemberFacility and Program since you may deduce it from the existing relationships:

select * from MemberFacility 
   where facilityId not in (select facilityId from MemberProgram); 

You would need the direct relationship only if individual members of a facility would or would not participate to the program a facility is enrolled in.

huangapple
  • 本文由 发表于 2023年5月20日 22:39:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76295771.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定