简体   繁体   中英

MySQL - EER Diagram - A group must have certain type of member

I'm trying to create a database, one part of my database is that, there are different Groups and there are Members in them. There are some requirements, a group MUST have a member wearing red cloth, and a member wearing yellow and a member wearing blue. It can have members wearing other colour but is optional for the group to exist.

I'm not sure how can I do it in an elegant way. This is my current concept:

我的EER

Your current concept is wrong. It seems to imply that "a group has one or more members", "each member is wearing red", "each member is wearing blue", "each member is wearing yellow", and "each member is zero or more members wearing anything".

A more correct solution would be the following (please excuse my short-hand notation, it's just quickly mashed up in Visio):

在此处输入图片说明

Group is now connected directly to the sub-types of Member . Each member is either a member wearing red, a member wearing blue, a member wearing yellow, or a member wearing something else. The common attributes are in the Member table.

As you can see, it's still not a very elegant as a DB solution. As Strawberry noted in the comments of OP, this kind of logic should probably be implemented at the application layer rather than in DB. In that case you could have a simple two-table solution with Group and Member , an attribute for Colour in Member , and somewhere in your application a rule that states that a group is only valid if it has these certain members.

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