locking - SQL Server : lock table to block other sessions trying to read the table -


i need able lock table in sql server while doing work. lock needs block other sessions reading table. when work complete table needs unlocked.

in mysql have done using:

lock tables [table] write 

at point other sessions blocked when trying read table, until table unlocked.

unlock tables 

now blocking stop.

is possible in sql server?

begin transaction       select * tablename (tablockx)   /* stuff here */  commit transaction 

tablockx obtain exclusive lock on table , other users not able read or update data until commit transaction yourself.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -