Requirement: to have a thumbs up/thumbs down “vote” on a given page. It should track who voted, when, and what their choice was. This will be used to show a total vote count, possibly a chart to show votes over time.
SQL Table
- PageId BigInt FK PK
- UserId BigInt FK PK
- Vote TinyInt
- DateVoted DateTime
PageId and UserId are, together, the PK for the table. Possible values for the “Vote” field are 1 and -1. The DateVoted field will be set to DateTime.UtcNow on vote.
Are there fields I’m missing that you would consider important?
On-page implementation will be vaguely similar to YouTube’s.
I would say the right answer depends on your requirements. As long as this is all the information you need and your foreign keys work with the related tables, then it seems fine to me.
Note that
tinyintis not signed so -1 is not an option. So I’d usebitinstead (0 = downvote, 1 = upvote).