我需要创建一个调查,将答案存储在数据库中.我只是想知道在数据库中实现这一点的最佳方式是什么,特别是在所需的表中.这项调查包含不同类型的问题.例如:注释、多项 Select 题的文本字段,以及可能包含多个答案的问题(即勾选所有适用项).

我提出了两种可能的解决方案:

  1. 创建一个包含

    我不认为这是最好的方式

  2. 我想到的另一件事是

    一个简单的例子:

    tblSurvey:调查

    tblQuestion:QuestionID,SurveyID,QuestionType,问题

    tblAnswer:回答,UserIDQuestionID,回答

    tblUser:用户ID,用户名

    我的问题是

如果有任何 idea 和建议,我将不胜感激.

推荐答案

I think that your model #2 is fine, however you can take a look at the more complex model which stores questions and pre-made answers (offered answers) and allows them to be re-used in different surveys.

- One survey can have many questions; one question can be (re)used in many surveys.
- One (pre-made) answer can be offered for many questions. One question can have many answers offered. A question can have different answers offered in different surveys. An answer can be offered to different questions in different surveys. There is a default "Other" answer, if a person chooses other, her answer is recorded into Answer.OtherText.
- One person can participate in many surveys, one person can answer specific question in a survey only once.

survey_model_02

Sql相关问答推荐

SQL -连接两个表的次数与第一个表中匹配的次数相同

查询将查找将标记设置为user2的用户

帮助修复查询以识别SQL DW中数据中的递归关系

如何在SQL查询中只比较日期时间的年份和月份(而忽略日期比较)?

JSON列之间的Postgr聚合

删除MariaDB数据库中的JSON数据

使用Lead获取下一个不同的日期

使用占位符向SQL INSERT查询添加 case

SQL -滞后于上一个非重复值

如何查询jsonb列是一个对象数组?

重新组合已排序的日期范围

UPDATE查询中的乐观锁

如何计算一个用户S的日常连胜?

Postgres SQL查询从字符串中获取邮箱地址

SQL中相同表内的VLOOKUP等价

如何向 mariadb 添加外键?

oracle中多行的跨日期范围的交集

在 SQL 查询中创建滚动日期

T-SQL - 返回每条记录的最近雇佣日期

在 MySql 数据库中的两个日期之间搜索