将问题数据存储到数据库中的最佳方法是什么? [英] What is the best approach to store question data into a database?

查看:94
本文介绍了将问题数据存储到数据库中的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个向导可以包含超过150个问题或只有10.每个问题可以不同于以前提出的问题。例如,可能有一个问题要求您回答是/否答案,但下一个问题可以包含具有四个选项的多项选择列表。还有一个机会,以填写一个完全开放的答案在这个向导中提出的问题。向导包含多个节。

There is a wizard that can contain over 150 questions or just 10. Each question can be different from the question asked before. For example, it is possible that one question requires you to answer a "Yes / No" answer, but the next one can contain a multiple choice list with four options. There also should be an opportunity to fill in a completely open answer to the question asked in this wizard. The wizard consist of multiple sections.

此向导的结果也应进行评估。例如:
上班时你忘记穿鞋了吗? 是/否如果用户回答是,我们应该评估这个,告诉他,他应该把他的鞋子在门口,所以他不会再忘记它。 (示例)

The results of this wizard should also be evaluated. For example: "Did you ever forget to put on your shoes when going to work?" "Yes/No" If the user answered yes, we should evaluate this and tell him that he should put his shoes at the door, so he won't ever forget it again. (example)

此向导的结果必须保存到数据库中,但是在一个表中执行此操作,只是将所有数据添加到此表中看起来很安静。
有没有人在这里有一个干净的解决方案,所以,例如,如果我们必须重建一个这样的向导,我们可以只使用相同的数据库?

The results of this wizard have to be saved into a database, but doing this in one table and just adding all data to this table looks quiet unhandy to me. Is there anyone here that has a clean solution so that for example if we ever have to rebuild a wizard like this, we can just use the same database?

推荐答案

你绝对不应该把它放在一个大表中。我的设计看起来像这样:

You definitely shouldn't try to put it all in one big table. My design would look something like this:

Id,名称,前言,AnyOtherInfoYouMightWantToStore

Id, Name, Preface, AnyOtherInfoYouMightWantToStore

Id,WizardId,Question,SortNumber

Id, WizardId, Question, SortNumber

Id,QuestionId,TypeId(radio,checkbox,free-text,multiline freetext ...),Name,SortNumber

Id, QuestionId, TypeId (radio, checkbox, free-text, multiline freetext...), Name, SortNumber

Id,UserId(我想您会有部分使用者帐户解决方案),QuestionId,AlternativeId

Id, UserId (I imagine you'd have some user account solution), QuestionId, AlternativeId

大致如此。所以一个向导可以包含许多问题,一个问题可以包含许多替代方案(yes + no radiobuttons是Alternative表中的一个记录,但是你也可以做更复杂的事情,例如一些复选框, ,其他文本字段)

Roughly like that. So that a wizard can contain many questions, and a question can contain many alternatives (yes + no radiobuttons would be one record each in Alternative table, but you could also do more complex things, such as a handful of checkboxes and, at the bottom, a "Other" textfield)

这篇关于将问题数据存储到数据库中的最佳方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆