数据库架构组织
我目前正处于构建日程安排网络应用程序(用于活动志愿者人员配置)的规划阶段,我有一个问题想问那些有更多经验的人。
背景: 有一个活动日历,任何用户都可以随时注册参加任何活动。 稍后,但在该活动之前,其中一名管理员将介入并从注册的人员中选择一个“员工列表”,其余的将被放入“备用列表”中。
到目前为止我一直在想的是,将会有一个事件表、一个用户表,然后是另外三个表:
- UserEvent
- 将用户映射到他们注册的活动。 并不暗示员工或 Alt 列表成员身份。
- 用户人员
- 将用户映射到他们注册的活动,并且恰好正在配备人员。
- 用户Alt
- 与 UserStaff 类似
问题就变成了两部分:
- 这是一个好方法吗?
- 这三个关联表中的每一个都应该有用户 ID 和事件 ID 吗?
第二个问题确实是我希望看到讨论的问题。 这似乎有很多重复的材料(UserStaff 或 UserAlt 中的所有内容都将始终在 UserEvent 中),因此我正在考虑为 UserEvent 表创建一个唯一的键,除了复合键之外,其他表(UserStaff 和UserAlt) 将参考。 从好的方面来说,重复的内容较少,从坏的方面来说,几乎每个查询都需要以这种方式引用一个中间表(UserEvent)。
希望我已经说得足够清楚了,并提前致谢。
I'm currently in the planning phase of building a scheduling web app (for volunteer staffing of events), and I've got a question for those with more experience.
Background:
There's a calendar of events, and any user at any time can register for any of the events. At a later time, but before that event, one of the admins will step in and select a "Staff List" out of those that registered, and the rest will be put into an "Alternate List".
What I've been thinking so far is that there will be an Event table, a User table, and then three others:
- UserEvent
- Maps users to events they registered to. Does not imply either the Staff nor the Alt list membership.
- UserStaff
- Maps users to events they registered to, and also happen to be staffing.
- UserAlt
- Similar to UserStaff
The question then becomes two part:
- Is this a good way to do it?
- Should each of those three associative tables have the user id and the event id?
That second question is really the one I'd like to see discussed. That seems like a lot of duplicated material (everything in either UserStaff or UserAlt will always be in UserEvent), so I was thinking of creating a unique key for the UserEvent table, in addition to the composite key, that the other tables (UserStaff and UserAlt) will refer to. On the plus side, there is less duplicated content, on the down side there's an intermediary table (UserEvent) that needs to be referenced in almost every query this way.
Hopefully I've been clear enough, and thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我将有下表:
ParticipantType.Name 是“参与者”或“工作人员”之一。
I would have the following tables:
ParticipantType.Name is one of "participant" or "staff".
这看起来不错,但您可能需要考虑将用户-事件关联表合并为一个,并在该表上有一列指示关联的目的,即事件、人员或 Alt。 这将有效地消除您在 UserEvent 表中描述的重复的需要,因为在大多数情况下,Staff 和 Alt 可以被视为 Event 的超集。
这种方法的一个好处是它允许存在多种类型的用户-事件关联,例如,如果您有一个用户是某个活动的工作人员但不是参与者,或者一个用户只是 Alt; 这种方法使您不必枚举所有可能的组合。 现在,如果您的设计明确指定只能拥有一组特定的用户参与类型,这可能会引入您不希望的分离程度; 您可能更愿意对用户对活动的参与级别设置明确的限制。 另一方面,如果您没有严格指定的集合,则该系统允许轻松添加更多参与角色(并且不会干扰现有的参与角色)。
This seems good, although you might want to consider combining your User - Event association tables into one, and having a column on that table that indicates the purpose of the association, i.e. Event, Staff, or Alt. This would effectively obviate the need for the duplication you describe in the UserEvent tables, since Staff and Alt could be considered to be supersets of Event for most purposes.
One benefit of this approach is that it allows for there to be multiple types of User - Event associations, such as if you have a User who is a Staffer for an Event but not a Participant, or a User who is just an Alt; this approach saves you from having to enumerate all the possible combinations. Now, if your design explicitly specifies that you can only have a certain set of User Participation types, this might introduce a level of dissociation you don't want; you may prefer to have explicit constraints on the set of participation levels that a User may have on an Event. If you don't have that tightly specified set, on the other hand, this system allows for adding more Participation roles easily (and without disturbing existing Participation roles).
不是对您问题的直接回答,但这是一个我喜欢的网站。 它有大量的示例模式。 我通常不会将它用作确定性的(当然),但有时它会给我一些我没有想到的想法。
Not a direct answer to your question, but here's a site I like. It's got tons (and tons) of sample schema. I generally don't use it as definitive (of course), but sometimes it will give me an idea on something I wasn't thinking of.