Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 sql update atomicity

Author  Topic 

ernest.morariu
Starting Member

2 Posts

Posted - 2012-09-19 : 06:24:54
Hi !

Suppose we have a table T with the following structure:
Id int primary key
A int

Let's also suppose the table T contais the following record :
Id A
1 5

I would like to know if the following sql is executed atomically:

Update T set T.A = T.A + 1 where T.Id = 1 and T.A < 10

Does this sql dipends on the current transaction isolation level ?

Supose there is another client that may execute concurrently the following sql command:

Update T set T.A = 50 where T.Id =1

Put it differently, is there any risk I can find in the field A the value of 51 ?(which would be undesirable for me)

Thank you !
Ernest





TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2012-09-19 : 10:30:51
you will not end up with A=51 with any isolation level. READ UNCOMMITTED does not apply to update statements and any other isolation level will not allow this to be violated (and T.A < 10).

Be One with the Optimizer
TG
Go to Top of Page

ernest.morariu
Starting Member

2 Posts

Posted - 2012-09-20 : 08:21:14

Thank you TG!

Ernest
Go to Top of Page
   

- Advertisement -