数据库设计:两次保存值?
我必须设计一个问卷系统。我们一起讨论了很多事情,包括如何把握答案,如何把握可能的答案。现在,我刚刚向我的同事屈服了,尽管我确实不同意。我只是想知道你对此的看法以及原因。 对我来说,两次保存相同的信息是一个非常糟糕的主意:
我们有一个表 Question_answer,它只保存一个问题 ID 和一个答案文本。 在另一个表中,我们保存答案,也带有文本字段。
我的想法是通过 id 将可能的答案链接到答案表,如果它是某种不同的答案,例如开放问题,我会将其放在可选的文本字段中......
I have to design a questionnaire system. We've been discussing a lot of things together, including how to hold answers, and how to hold the possible answers. Now, I've just given in to my collegue though I do disagree. I just want to know your opinions about it and why.
For me it's just a very bad idea to hold the same information twice:
We have a table question_answer, that just holds a question Id and an answer TEXT.
In another table, we hold answers, also with a TEXT field.
My idea was to just link a possible answer to the answer's table by id, and if it was some kind of different answer, like an open question, I would put it in a text field that is optional...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我可能会从包含最多数据的表格开始 - 在这种情况下,这可能是将给定采访的问题与答案联系起来的调查回复(我刚刚将其建模为一对受访者和外国代表)键)。
调查表将问题链接到标准答案。我已将可选答案放入“响应”表中,但它们可以改为进入“答案”表(或者它可以是标准答案加可选答案表的视图,但您喜欢)。
I would probably start from the table that is going to hold the most data - which in this case is likely to be the survey responses that link questions to answers for a given interview (which I have just modeled as a pair of Respondant and Representative foreign keys).
The Surveys table links questions to standard answers. I've put optional answers into the Responses table, but they could go into the Answers table instead (or it could be a view onto Standard answers plus Optional answers tables, however you prefer).