【问题标题】:Storing Exam Questions in a Database在数据库中存储考试问题
【发布时间】:2014-05-15 11:32:21
【问题描述】:

一年多来,我一直在考虑如何设计一个数据库来保存试题(时断时续,大部分时间都是关闭的)。

首先,简要描述一下我所追求的。我想设计一个足够灵活的数据库来存储不同的问题类型(例如,简答题或多项选择题),并且能够选择任意数量的这些问题作为考试进行存储。

我的问题是:

试题应该如何存储?

由于不同的问题类型需要存储不同的字段,如果我将它们都放在同一张表questions下,将会有很多额外的字段从未使用过。

如果我将问题类型分成不同的表,那么将 question_id 存储在一些 exam_questions 表中会更加困难,因为它们将来自不同的表。

我也想不出一种灵活的方式来存储信息。

例如,

questions
 - id
 - question
 - type (multiple choice, short response)
 - choice_1 ( used for multiple choice questions)
 - choice_2
 - choice_3
 - choice_4
 - choice_5
 - answer (short response answer here, or just a/b/c/d/e for multiple choice, t/f for true or false)

会推荐这样的设计吗?如果没有,有人有什么建议吗?

我还有一个问题:

如果我想存储学生对其中一项考试的回答,这样存储它们会不会效率低下?

exam_responses
  - id
  - student_id
  - exam_id
  - question_id or question_number
  - response
  - mark

提前谢谢你。如果您想了解任何其他信息,或者此问题有任何问题,请给我留言,我会尽快修复。

【问题讨论】:

  • 最好把问题和答案分开

标签: sql database database-design database-schema


【解决方案1】:

我会有单独的问答表,并使用 question2answer 表加入它们

question
--------
 - id
 - question
 - type (multiple choice, short response)

answer
------
 - id
 - GUIorder (so you can change the sort order on the front end)
 - answer

question2answer
---------------
 - questionid
 - answerid

现在,就构建问题而言,一切都是动态的,并且您没有空列。 快速加入让您回到主要问题的所有部分

您的exam_responses 表现在可以包含以下内容

- id
- questionid
- answerid
- studentid
- response
- mark

【讨论】:

  • 感谢您抽出宝贵时间回复!我有一个快速的问题。是否有任何理由使用 question2answer 表而不是将 questionid 存储在 answer 表中?你能举个例子吗?问候,米克。
  • @Mick 这样您就可以重复使用答案 - 即。对多个问题的判断是对还是错 - 这完全取决于您的问题的结构。
【解决方案2】:

我认为在问题表中为每个响应存储五列并不是一个好的设计。如果问题的选项数变为 6,您将不得不再添加一列。此外,如果只有两个选项,其余列将保持为空。所以最好放在两个单独的表中:

questions
 - id
 - question
 - type (multiple choice, short response)
 - answer (short response answer here, or just a/b/c/d/e for multiple choice, t/f for true or false)

question_choices
- id
- question_id
- choice

然后,您可以根据 questions.id=question_chocies.question_id 条件加入每个特定问题的选项列表。

如果是考试回复,您也应该分成两个表格,以免重复有关每个考试问题的学生 ID、考试和分数的信息。所以应该是这样的:

student_exam
  - id
  - student_id
  - exam_id
  - mark

student_exam_responses
  - exam_id
  - question_id or question_number
  - response

这两个表可以根据student_exam.id=student_exam_responses.exam_id条件连接起来。

【讨论】:

    猜你喜欢
    • 2017-01-27
    • 2011-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 1970-01-01
    • 2011-04-26
    相关资源
    最近更新 更多