Database design 具有重复组的测量数据库设计

Database design 具有重复组的测量数据库设计,database-design,conditional,conditional-statements,survey,repeat,Database Design,Conditional,Conditional Statements,Survey,Repeat,我有一个简单的调查数据库,里面有一组线性的问题。数据库设置如下 Survey Table id: PK (other details) Question Table id: PK survey_id: FK (other details) Response Table id: PK question_id: FK (other details) 我被要求修改调查,以允许N个重复问题组。比如说 Question Rule Table id: PK question_id: FK respon

我有一个简单的调查数据库,里面有一组线性的问题。数据库设置如下

Survey Table
id: PK
(other details)

Question Table
id: PK
survey_id: FK
(other details)

Response Table
id: PK
question_id: FK
(other details)
我被要求修改调查,以允许N个重复问题组。比如说

Question Rule Table
id: PK
question_id: FK
response_validation_rule (possibly a regex pattern)
next_question_id
  • 你叫什么名字?你的地址是什么
  • 你喜欢运动吗
  • 你做什么运动
  • 你打什么位置
  • 你玩别的运动吗?如果是,则转到3,否则转到6
  • (补充问题)
  • 设计具有重复组的调查数据库的最佳方法是什么

    我考虑过使用问题规则表来引导问题的方向。比如说

    Question Rule Table
    id: PK
    question_id: FK
    response_validation_rule (possibly a regex pattern)
    next_question_id
    

    这是实施重复组问题的最佳方式吗?我还猜测,数据也很难正常化。任何建议都将不胜感激。

    问题表中的自我多对多关系可能会有所帮助
    多对多关系将一个问题与其他问题联系起来

    要达到获取相关问题的标准:

    如果是,请转到3

    可以通过将FK从应答表添加到多对多表来完成。

    大概是这样的:
    我只是建议不要在相关问题表中使用代理标识符列

    • 复合PK将是
      {main question id,related question id,answer id}
    • 检查约束将是
      {main question id related question id}

    非常感谢您如此完整的答复。对于答题表,如何处理开放式问题?不客气。我认为您应该在调查表上有一个问题计数列,然后在问题表中有一个问题编号列,带有检查机制(触发器或应用程序逻辑)来检查问题编号是否正确