如何用问题和答案构建数据库?
我将制作一个使用数据库的简单应用程序。我可能需要一些关于如何构建它的指导。
我将制作提问程序。我的想法是。
- 一张桌子有问题
- 一张桌子 与问题的难度
- 一张表,其中包含问题的类别 问题
但是,我该如何处理答案呢?将它们作为问题表中的单独列吗?这听起来像是一种不好的做法。(另外,我在哪里有正确的答案)
每个问题都有 5 个答案,其中只有一个是正确的。
I am going to make a simple application that uses a database. I could need some guidance on how to structure it.
I shall make question program. What I have in mind is.
- One table with questions
- One table
with the difficulity of the question - One table with the category of the
question
However, what do I do with the answers? Have them as seperate columns in the question-table? It sounds like a bad practice.(Also, where do I have the correct answer)
Each question will have 5 answers where only one of them is correct.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
答案表。主键可以是(问题 ID、答案 ID),其中答案 ID 可以是(a、b、c、d、e)。其他字段认为合适,还包括一个 Correct_answer 二进制字段,该字段为 1 表示问题正确。
Answer table. Primary key can be (Question ID, Answer ID) where Answer ID can be, say, (a, b, c, d, e). Other fields as seen fit, and also include a correct_answer binary field which is 1 for the question that is correct.
有一个
answers
表,其外键指向questions
表的主键Have a
answers
table with foreign key pointing to primary key ofquestions
table为什么不将所有问题数据保存在一张表中?类似于:
question_id | 问题ID类别_id |难度|正确答案 | Question_text
其中,category_id 是“类别”表的外键, Correct_answer 是问题表的外键。
要获得答案,您可以执行以下操作
answer_id |问题 ID |答案文本 |答案顺序
问题 ID 是指向问题表的外键 - 答案顺序是可用于对每个问题的答案进行排序的数字
Why not keep all your question data in one table? Something like:
question_id | category_id | difficulty | correct_answer | question_text
Where category_id is a foreign key to a 'Category' table, and correct_answer is a foreign key to the questions table.
For answers, you can do something like
answer_id | question_id | answer_text | answer_order
Question id is a foreign key pointing to the questions table - answer order is a number you can use to sort the answers for each question