轮询数据库架构

Ric*_*nop 23 mysql database-schema

民意调查的最佳数据库架构是什么?一对多的关系对此有利吗?我正在考虑有两张桌子:

poll_questions
    int id
    varchar body
    datetime created_at
    datetime updated_at

poll_answers
    int id
    varchar body
    int votes default 0
    int question_id (foreign key to poll_questions.id)
    datetime created_at
    datetime updated_at
Run Code Online (Sandbox Code Playgroud)

然后还会有第三个表来跟踪谁投票给答案,这样用户只能投票一次:

poll_voting_history
    int id
    int question_id (foreign key to poll_questions.id)
    int answer_id (foreign key to poll_answers.id)
    int user_id (foreign key to the id in the users table)
    datetime created_at
    datetime updated_at
Run Code Online (Sandbox Code Playgroud)

你的想法是什么?我在想它吗?

che*_*vim 13

架构看起来不错,是的,您还需要跟踪用户投票.


小智 5

注意:poll_answers表的"votes"列不是必需的.可以通过查询Poll_voting_history表来确定投票.