0

我正在实施一个竞赛系统,用户必须在其中选择多个问题的正确答案。每周都有一组新问题。我正在尝试找到将用户参与存储在数据库中的正确方法。现在我有以下数据模型:

 Participation                     Week
+--------------+                  +--------------+
| Id           |     +----------->| Id           |<-+
| UserId       |     |            | StartDate    |  |
| WeekId       |-----+            +--------------+  |
+--------------+                                    |
                                   Question         |
                                  +--------------+  |
                                  | Id           |  |
                                  | WeekId       |--+
                                  | Text         |
                                  +--------------+

我想出的唯一解决方案是添加一个将参与与问题相关联的答案表,如下图所示:

    Participation                     Week
   +--------------+                  +--------------+
+->| Id           |     +----------->| Id           |<-+
|  | UserId       |     |            | StartDate    |  |
|  | WeekId       |-----+            +--------------+  |
|  +--------------+                                    |
|                                     Question         |
|       Answer                       +--------------+  |
|      +------------------+    +---->| Id           |  |
+------| ParticipationId  |    |     | WeekId       |--+
       | QuestionId       |----+     | Text         |
       | Value            |          +--------------+
       +------------------+

我不链接这个解决方案非常好,因为它允许参与者回答来自不同周的问题。将 WeekId 添加到答案中没有帮助。

表示此信息的正确方法是什么?

4

3 回答 3

1

You could remove the Id field in the table Participation, and use (UserId, WeekId) as composed/concatenated primary key for the table Participation. The field ParticipationId in the table Answer you have to replace then by the pair (UserId, WeekId) as foreign key reference to the table Participation. If your database system allows it, you can define then the fields (QuestionId, WeekId) in the table Answer to reference (Id, WeekId) in the table Question. Maybe for this you have to define an index on the pair (Id, WeekId) in the table Question before.

于 2009-07-30T16:10:41.423 回答
0

你真的需要将参与与它的周联系起来吗?你可以通过问题得到它

所以:

  • 答案(Id,UserId,QuestionId,值)
  • 问题(Id,WeekId,文本)
  • 周(ID,开始日期)
于 2009-07-30T16:07:44.923 回答
0

我个人认为你在这里有正确的实施。

ParticipationId 链接到参与的 ID,该 ID 以用户和周为键。您的 Question 表也以 WeekId 为键。

因此,您一直都有适当的参考资料。如果不是这种情况,我认为我们需要查看一些数据

于 2009-07-30T16:08:29.853 回答