is sql server transaction atomic

£可爱£侵袭症+ 提交于 2019-12-03 14:53:48

Yes they are atomic but that does not mean that you will get the behaviour that you want here! The property you need to look at is isolation.

To achieve the exclusion that you require you would need to make the SELECT operation on the single value mutually exclusive. You can do this by requesting an Update lock (make sure the WHERE predicate can be found through an index to avoid locking unnecessary extra rows)

SELECT * FROM foo WITH(ROWLOCK,UPDLOCK) WHERE bar='baz'

Note this lock will be held until your transaction commits however not released at the end of the critical section but that is always going to be the case if you have updated the value anyway.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!