View Single Post

   
  #2 (permalink)  
Old 04-03-2008, 02:49 PM
Willem Bogaerts
 
Posts: n/a
Default Re: reliably increasing a number in a concurrent setting

> I have a table with two fields, VARCHAR playername and INT score. When
> the player wins, I want to increase her score. The player might play
> multiple games at the same time, so if I read the old score, increase it
> and write it back, I run the risk of overwriting a concurrent update that
> does the same thing.


Not if you do it in the same statement:

UPDATE yourtable SET score=score+1 WHERE playername='Some name';

Every single SQL statement is atomic, meaning that concurrency problems
do not occur within one statement.

Best regards,
--
Willem Bogaerts

Application smith
Kratz B.V.
http://www.kratz.nl/
Reply With Quote