如何在数据库中存储多个选择问题 [英] How Should I Store Multiple Choices Questions In Database
问题描述
您好我想知道存储多项选择题的方法并将其显示在网页上。
我已经显示了单一答案问题,但必须更新多个选项
在表格中我有问题ID,用户ID,主题ID,没有正确答案。
Hello i want to know the approach to store multiple choice questions and display it on web page .
I already did display of single answer questions, but have to update it multiple choices
in table i have question id , user id, subject id, no of correct answers.
推荐答案
这可能是一种结构方式:
This could be one way to structure:
问题
Id
Text
答案
Id
文字
QuestionId
CorrectAnswers
QuestionId
AnswerId
Question
Id
Text
Answers
Id
Text
QuestionId
CorrectAnswers
QuestionId
AnswerId
有一个单独表格的正确答案的理由是一个问题可以有多个正确的答案。如果不是这种情况,您可以省略第三个表,只需将名为 CorrectAnswerId
的字段添加到问题
表。
如果有多个问题可以使用相同的答案,你也可以从中删除 QuestionId
答案
表并将 IsCorrect
字段添加到 CorrectAnswers
表。这将减少数据库的大小。但是,如果您对一个问题进行了更改以回答,则会针对使用该问题的所有问题对其进行更改。
Reason for having a separate table for correct answer is that one question can have more than one correct answers. If that is not the case, you can omit third table and just add a field called CorrectAnswerId
to Questions
table.
If there is a chance that same answer can be used for multiple questions, you might as well remove QuestionId
from Answers
table and add IsCorrect
field to CorrectAnswers
table. This will reduce the size of your database. However, if you make change to answer for one question, it will change it for all the questions that are using it.
这篇关于如何在数据库中存储多个选择问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!