views:

61

answers:

1

I'm trying to model a site similar to StackOverflow. It has a set of users and questions, and user vote on questions. Each user can only have one vote on each question.

What should the structure of my "VotesOnQuestions" table look like:

  1. Should I have an auto-generated "VoteID" column?
  2. How do I disallow, at the schema level, a user from having multiple votes on a question?
  3. Should I, instead of a VoteID column, just use (UserID, QuestionID) as a primary key?
+6  A: 

Use the Primary Key UserID, QuestionID.

That will enforce your requirement, and optimze searches.

astander
although, I like user_id and question_id, personally
arbales