How to control concurrency in SQL Server SELECT queries? -


how control concurrency in sql server select queries?

here problem, these sql queries below going execute @ same time should not take same record.

how handle this?

session 1:

begin tran  declare @id int  select top 1 @id = id  dbo.table_1  update dbo.table_1 set is_taken = 1 id = @id  commit tran 

session 2:

begin tran  declare @id int  select top 1 @id = id  dbo.table_1  update dbo.table_1 set is_taken = 1 id = @id  commit tran 

as mentioned in comments, sql server takes care of isolation, hence can run update without select:

update top (1) dbo.table_1 set is_taken = 1 

i guess meant have condition on select avoid updating same record each time:

update top (1) dbo.table_1 set is_taken = 1 output inserted.id @id is_taken != 1 

Comments

Popular posts from this blog

javascript - how to protect a flash video from refresh? -

android - Associate same looper with different threads -

visual studio 2010 - Connect to informix database windows form application -