对于多项选择测验引擎来说,数据库模式的良好设计是什么?

发布于 2024-10-16 08:11:20 字数 547 浏览 1 评论 0原文

我有一个项目来创建一个 asp.net mvc 站点来生成测验。 规范如下:

  1. 对于每个访问该网站的用户,她/他都会得到一个测验。
  2. 每个测验都包含一些多项选择题。
  3. 每个问题包含一个问题和 5 个互斥的选项。

我能想到的最简单的模型如下:

    public class Problem
    {
        public int ProblemId { get; set; }
        public string Question { get; set; }
        public string A { get; set; }
        public string B { get; set; }
        public string C { get; set; }
        public string D { get; set; }
        public string E { get; set; }
    }

我不确定它是否好。 您能给我一个更好的设计建议吗?

I have a project to create an asp.net mvc site to generate a quiz.
Here is the specification:

  1. For each user visiting the site, she/he gets a quiz.
  2. Each quiz contains some multiple-choice problems.
  3. Each problem contains a question and 5 mutually-exclusive choices.

The simplest model I can think of is as follows:

    public class Problem
    {
        public int ProblemId { get; set; }
        public string Question { get; set; }
        public string A { get; set; }
        public string B { get; set; }
        public string C { get; set; }
        public string D { get; set; }
        public string E { get; set; }
    }

I am not sure it is good.
Could you give me a suggestion for a better design?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

∞梦里开花 2024-10-23 08:11:20

属性 A 到 E?不,谢谢!我的表格布局如下:

Quiz (int QuizId, ...)
Problem (int ProblemId, int QuizId, string Question)
Answer (int AnswerId, int ProblemId, int Index, string Answer)

字段名称应该是不言自明的(索引是单个问题答案的排序索引,如果它们的顺序很重要)

Properties A through E? No thank you! I'd lay out my tables as follows:

Quiz (int QuizId, ...)
Problem (int ProblemId, int QuizId, string Question)
Answer (int AnswerId, int ProblemId, int Index, string Answer)

The field names should be self-explanatory (Index is the sort index for the answers of a single question, if their order matters)

緦唸λ蓇 2024-10-23 08:11:20

简单直观的设计总是最好的,因为它们真的很简单,我们开始怀疑自己;-)。除了您还可以将正确答案与问题本身一起存储之外,您做得很好。那么它就不再只是一个问题了。现在是 ProblemAndAnswer 或 QuizItem。

因此,将其作为多个列存储在单个表中就可以了。 但您还需要理解它的含义。这意味着您假设一个问题总是有 5 个选择。如果少于 5 个,那么没关系,因为您可以存储空值。但如果你想要更多怎么办?这是单表模型开始崩溃的时候。您现在会开始认为一个问题确实可以有 1 个或多个选择,并且希望拆分为父子表......现在您已经做出了明智的决定;-)

Simple and intuitive designs are always the best and since they are really simple, we start doubting ourselves ;-). You are doing good except you can also store the correct answer with the Problem itself. Then it is no longer just a Problem. So now it is ProblemAndAnswer or QuizItem.

So this is all OK to store in a single table as multiple columns. But you also need to understand what it means. This means that you are making an assumption that a question is always going to have 5 choices. If you going to have less than 5 then it is ok as you can store nulls. But what if you are going to have more? This is when the single table model starts falling apart. You would now start thinking that a Question really can have 1 or more choices and would want to split into parent child tables....now you have made a well-informed decision ;-)

最终幸福 2024-10-23 08:11:20

Question 有一个 id 和一个 description,它是问题的文本(“猫是秘密的狗吗?”)。

编辑:此外,Question 表有一个 Correct_answer_id,它对应于 Answer 表中的正确行。

Answer 有一个 question_id,将其链接回其 Question,以及一个 description,即文本答案(“这取决于你的猫的颜色。”)。

使用此架构,问题没有硬编码的答案数量。

The table Question has an id and a description, which is the text of the question ("Are cats secretly dogs?").

Edit: Additionally, the Question table has a correct_answer_id, which corresponds to the correct row in the Answer table.

The table Answer has a question_id, linking it back to its Question, and a description, which is the text of the answer ("It depends on the color of your cat.").

With this schema, questions don't have a hardcoded number of answers.

瞳孔里扚悲伤 2024-10-23 08:11:20

我正在研究相同类型的数据库结构。最好有一个选项表来针对特定问题 ID 插入选项。测验 ID 是一个单独的表,其中包含问题 ID 和测试持续时间。

I am working on same kind of database structure. It is better to have a choices table to insert choices against a specific question id. Quiz ID is a separate table that includes questionids and duration of test.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文