高效的方式来存储动态的问卷? [英] Efficient way to store a dynamic questionnaire?

查看:136
本文介绍了高效的方式来存储动态的问卷?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在参照<一个href="http://stackoverflow.com/questions/4626590/whats-an-effecient-way-to-store-a-questionnaire-in-a-database"标题=什么是存储的调查问卷在数据库中?一个有效的方法>这个问题,我面对几乎相同的情况下,除了在我的情况下,该问题可能是静态的(这是受从时间更改为一次,我仍然认为这不是一个好主意,添加列每个问题,但即使我决定加入,应该如何规定的答案/从中检索),但答案是不同的类型,示例答案可能是肯定的/没有,列表项,自由文本,列表项目或自由文本的(其他,请注明)的,多选择的列表项等。

In reference to this question, I am facing almost the same scenario except that in my case, the questions are probably static (it's subject to change from time to time, and I still think it's not a good idea adding columns for each question, but even I decided to add, how should the answers be specified/retrieved from), but the answers are in different types, for examples the answer could be yes/no, list-items, free text, list-items OR free text (Other, Please specify), multiple-selectable-list items etc.

什么是实现这样的一个有效的方法?

What would be an efficient way to implement this?

推荐答案

摆振,我已经写了四部分的文章,解决了这个问题 - 看的创建一个动态的,数据驱动的用户界面。本文着眼于如何让用户定义哪些数据存储有关用户,所以它不是你的问题的一个精确的检查,但它是pretty的接近。也就是说,我的文章展示了如何让最终用户定义的数据存储的类型,它是沿着你想要的线路。

Shimmy, I have written a four-part article that addresses this issue - see Creating a Dynamic, Data-Drive User Interface. The article looks at how to let a user define what data to store about clients, so it's not an exact examination of your question, but it's pretty close. Namely, my article shows how to let an end user define the type of data to store, which is along the lines of what you want.

下面ER图给出了数据模型的要点:

The following ER diagram gives the gist of the data model:

下面, DynamicAttributesForClients 是表格,指示什么用户创建的属性用户想要跟踪他的客户。总之,每个属性都有一个 DataTypeId 值,该值指示是否它是一个布尔属性,文本属性,数字属性,等等。在你的情况,该表将存储调查的问题。

Here, DynamicAttributesForClients is the table that indicates what user-created attributes a user wants to track for his clients. In short, each attribute has a DataTypeId value, which indicates whether it's a Boolean attribute, a Text attribute, a Numeric attribute, and so on. In your case, this table would store the questions of the survey.

DynamicValues​​ForClients 表保存存储为特定客户的特定属性的值。在你的情况,该表将存储在回答调查的问题。实际值存储在 DynamicValue 列,它的类型是 SQL_VARIANT ,允许任何类型的数据 - 数字,位,串等 - 将存储有

The DynamicValuesForClients table holds the values stored for a particular client for a particular attribute. In your case, this table would store the answers to the questions of the survey. The actual value is stored in the DynamicValue column, which is of type sql_variant, allowing any type of data - numeric, bit, string, etc. - to be stored there.

我的文章没有解决如何处理多项选择题,其中,用户可以选择从选项preSET列表中的一个选项,但提高了数据模型,使这是pretty的简单。您可以创建一个名为新表 DynamicListOptions 以下列:

My article does not address how to handle multiple-choice questions, where a user may select one option from a preset list of options, but enhancing the data model to allow this is pretty straightforward. You would create a new table named DynamicListOptions with the following columns:

  • DynamicListOptionId - 主键
  • DynamicAttributeId - 指定什么属性这些问题都与相关
  • OptionText - 选项文本
  • DynamicListOptionId - a primary key
  • DynamicAttributeId - specifies what attribute these questions are associated with
  • OptionText - the option text

所以,如果你有这是一个选择题的选项,你会填充与查询返回的选项在用户界面的下拉列表中选择属性:

So if you had an attribute that was a multiple-choice option you'd populate the drop-down list in the user interface with the options returned from the query:

SELECT OptionText
FROM DynamicListOptions
WHERE DynamicAttributeId = ...

最后,你将存储在 DynamicValues​​ForClients.DynamicValue 栏选择 DynamicListOptionId 值记录列表选项,他们选择(或使用 NULL ,如果他们没有选择的项目)。

Finally, you would store the selected DynamicListOptionId value in the DynamicValuesForClients.DynamicValue column to record the list option they selected (or use NULL if they did not choose an item).

举一个通读文章。有一个完整的,工作演示可以下载,其中包括完整的数据库和模型。此外,四篇文章组成的系列深入探讨了数据模型,并展示如何构建一个基于Web(ASP.NET)的用户界面,让用户定义动态属性,如何显示它们的数据录入,等等

Give the article a read through. There is a complete, working demo you can download, which includes the complete database and its model. Also, the four articles that make up the series explore the data model in depth and show how to build a web-based (ASP.NET) user interface for letting users define dynamic attributes, how to display them for data entry, and so forth.

快乐编程!

这篇关于高效的方式来存储动态的问卷?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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