4

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?
ripper234
  • 222,824
  • 274
  • 634
  • 905
  • 2
    Exact duplicate: http://stackoverflow.com/questions/1843222/do-link-tables-need-a-meaningless-primary-key-field – OMG Ponies Dec 27 '09 at 18:01

1 Answers1

8

Use the Primary Key UserID, QuestionID.

That will enforce your requirement, and optimze searches.

Adriaan Stander
  • 162,879
  • 31
  • 289
  • 284