轮询数据库架构 [英] Poll Database Schema
本文介绍了轮询数据库架构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最适合轮询的数据库架构是什么?一对多关系对此有好处吗?我正在考虑有两个表:
What is the best database schema for polls? Is one-to-many relationship good for this? I'm thinking about having two tables:
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
然后还有第三张表,用于跟踪谁对答案投票,因此用户只能投票一次:
Then there would also be third table for tracking who voted for an answer so users are able to vote only once:
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
您有什么想法?我在想对吗?
What are your thoughts? Am I thinking about it right?
推荐答案
The schema looks good, and yes, you'd need to track the user votes as well.
这篇关于轮询数据库架构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文