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.
Author |
Topic |
sasan_vm
Yak Posting Veteran
51 Posts |
Posted - 2014-05-21 : 15:42:07
|
Hello,I have a table , any row must be reserved exclusively on users request (many request received at same time). How to select a row exclusive, guarantee cannot be selected by another ?Regards,sasan. |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-05-21 : 16:31:45
|
What is the duration and purpose for which you need to reserve this row? If it is for anything other than for purposes of updating/retrieving data as part of a query, the preferred approach would be implement the logic without locking the table - for example, another column in the table that indicates whether a row is locked or not, and by whom. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2014-05-21 : 16:35:01
|
http://stackoverflow.com/questions/4596972/how-to-exclusively-lock-a-row-that-prevent-crud-operationTara KizerSQL Server MVP since 2007http://weblogs.sqlteam.com/tarad/ |
|
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-05-22 : 07:36:31
|
The first method that that stackoverflow response suggests - namely, using XLOCK in combination with ROWLOCK does not work one would intuitively expect (apparently due to the optimizations that SQL Server does). The alternative - using TABLOCK - will not allow any rows to be read. |
|
|
|
|
|