序
本文主要简述一下不同sql语句并发update的情况。
指定主键update
update tableA set owner = ? where id = ?
指定主键和版本号
update tableA set owner = ? where id =? and version = ?
指定主键及与更新字段相关的条件
update tableA set owner = ? where id = ? and owner =?
更新值与原值相关
update tableA set totalNum = totalNum + ? where id = ?
相当于如下:
1) open a transaction
2) fetch the data (SELECT totalNum FROM tableA WHERE id = ?;)
3) do your work (totalNum + amount)
4) update the data (UPDATE tableA SET totalNum = ? WHERE id = 1;)
5) commit