Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Poll Database Schema

Tags:

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?

like image 393
Richard Knop Avatar asked Feb 15 '10 08:02

Richard Knop


People also ask

What is poll in database?

You can use the polling statement to read or update data in a SQL Server database table. You can use the query notification statement to only read data in a SQL Server database table. Polling informs you about the actual data that has changed.


1 Answers

The schema looks good, and yes, you'd need to track the user votes as well.

like image 83
cherouvim Avatar answered Oct 15 '22 11:10

cherouvim