条件问卷的数据库设计

Database Design for Conditional Questionnaire

我正在设计一个数据库架构来支持用户可以提交请求(针对 him/herself 或代表其他人)的业务案例。为处理和完成请求,系统将 提示提交者根据他们对先前问题的回答提出问题 。也就是说,下一题是根据当前题的答案有条件的。

每个问题都有一个关联的类型,这将驱动该特定问题的用户表单。 boolean 类型的问题表示答案的 Yes/No 个单选按钮。 multiple 类型的问题表示多项选择答案,用户将 select 多个单选选项之一。

我有两个问题:

  1. 如何修改我的架构以 "link" 多项选择题的答案? (即"the following answers are available for question X.")
  2. 答案应该如何驱动下一个问题? (即 "for question #1, if answer A is chosen, then GOTO question 5")

我的 question_relationships table 会让我指定问题 1 是问题 5 的父级,问题 5 是问题 6 的父级。但我确实需要答案来驱动这个逻辑.

question
    -id         
    -question_name
    -question_text
    -question_hint
    -question_type (boolean, multiple)  

question_relationship
    -id                 
    -fk_parent_question_id
    -fk_child_question_id

request
    -id         
    -person_id  
    -submitter_id
    -submit_date
    -status 

request_answer
    -id
    -fk_request_id
    -fk_question_id
    -answer_text
    -answer_boolean

我在db design - survey/quiz with questions and answers中看到了答案,但我相信我的情况有点不同。

A table 有一个关联的填空(命名)语句又名 predicate。使其成为真实语句的行进入 table。使其成为虚假陈述的行被排除在外。这就是我们解释 table(基础、视图或查询)并更新基础的方式。每个table代表一个应用关系。

(所以你的2的谓词式引用是如何给出table的意思。因为那么JOIN的意思是参数意思的AND,而UNION是OR,EXCEPT是AND NOT, etc.)

  1. How can I modify my schema to "link" answers to multiple choice questions? (ie "the following answers are available for question X.")
// question [question_id] has available answer [answer_id]
question_answers(question_id, answerid)
  1. How should the answers drive the next question? (ie. "for question #1, if answer A is chosen, then GOTO question 5")
// for question [this_id] if answer [answer_id] is chosen then go to question [next_id]
next_question(this_id, answer_id, next_id)

PS
通过 tables 表示图 (nodes with edges between them) 的方式有很多种。这里的节点是问题,边是这个-下一个问题对。不同的 table 支持不同种类的图和不同的读取和更新模式。 (我选择了一个反映你的应用程序的,但将我的答案框起来以帮助你自己通过适当的设计找到你的最佳代表。)

PPS
如果不同的用户跟踪问题可能意味着哪个问题跟在另一个问题之后是上下文相关的:

// in context [this_id] if answer [answer_id] is chosen then go to context[next_id]
next_context(this_id, answer_id, next_id)

什么是 "context" 取决于您申请中未提供的方面。您给出的内容表明您唯一的上下文概念是当前问题。此外,根据上下文包含的内容,此 table 可能需要规范化。您可能需要当前上下文与当前问题的独立概念。 (主题:finite state machines。)