title: Voting System: Should I use a SQL Trigger or more Code?
body: <p>I'm building a voting system whereby each vote is captured in a votes table with the <code>UserID</code> and the <code>DateTime</code> of the vote along with an <code>int</code> of either <strong>1</strong> or <strong>-1</strong>.</p>
  
  <p>I'm also keeping a running total of <code>TotalVotes</code> in the table that contains the item that the user actually voted on.  This way I'm not constantly running a query to <code>SUM</code> the Vote table.</p>
  
  <p>My Question is kind of a pros/cons question when it comes to updating the TotalVotes field. With regards to code manageability, putting an additional update method in the application makes it easy to troubleshoot and find any potential problems. But if this application grows significantly in it's user base, this could potentially cause a lot of additional SQL calls from the app to the DB.  Using a trigger keeps it "all in the sql family" so to speak, and should add a little performance boost, as well as keep a mundane activity out of the code base.</p>
  
  <p>I understand that premature optimization could be called in this specific question, but since I haven't built it yet, I might as well try and figure out the better approach right out of the gate.</p>
  
  <p>Personally I'm leaning towards a trigger.  Please give me your thoughts/reasoning.</p>