带有问题和答案的数据库结构
我正在设计一个包含问题、答案和类别的数据库。
一个问题可以属于多个类别,一个类别可以有多个问题。 所以这个关系是多对多的。
一张问题表
一类表
一张表包含上面两个表的主键
所以现在我的问题是,是否有必要或“更好”将答案(a,b,c,d,e)存储在名为answers的自己的表中?那么答案表就有一个外键指向问题表的主键。
或者我应该在问题表中只包含 5 列,其中包含答案以及正确答案吗?
根据我的阅读,一对一的关系是不正常的。
提前致谢!
I am designing a database that contains questions, answers and categories.
One question can belong to many categories, and one category can have many questions.
So this relationship is a many-to-many.
One question table
One category table
One table containing primary keys of the two tables above
So now my question is, is it necessary or "better" to store answers (a, b, c, d, e) in a own table named answers? Then the answer table has a foreign key to the primary key in the question table.
Or should I just have 5 columns in the question table containing the answers as well with the correct answer?
After what I read it is not normal to have a one - to - one relationship.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
制作一个单独的
answers
表。有两个好处:答案表应如下所示:
现在,您将一个答案存储在一行中...以及序列号(a、b、c.. 或 1、 2,3.. 或 i, ii, iii,... 无论如何)您使用
serial_number
字段。is_ Correct
指向正确答案。您可以通过以下方式选择答案列表
Make a separate
answers
table. There are two benefits:The answers table should look like this:
Now, you store one answer in one row... and for serial_number (a,b,c.. or 1,2,3.. or i, ii, iii,... whatever) you use
serial_number
field.is_correct
points to correct answer/s.You can select list of answers by
如果您确定总是会给出准确的答案(不多也不少),那么将它们作为问题表中的列是合理的。一般来说,它会简化您的查找过程并提高效率。但是,如果您有时或将来可能有不同数量的答案,那么您的答案应该有自己的表格。
If you know for certain that there will always be exactly give answers (neither more nor less), then it's reasonable to make them columns in the questions table. It'll simplify your look-up process and be more efficient, generally. However, if you sometimes have varying numbers of answers or might in the future, then your answers should have their own table.