1

I have a SQL Server 2008 database that contains a table of Items. Many users are viewing Items and can choose at any time to check out an available Item. I want to have a simple locking scheme where the user clicks an Item, the server then acquires a ROWLOCK, checks if the item is checked out already (reads the row), checks it out if available (updates the row), and then frees up the lock.

I have not been able to find any code examples showing how to do this completely. Most examples focus on a single statement, not multiple statements.

Wesley Tansey
  • 4,555
  • 10
  • 42
  • 69
  • Maybe you can read http://stackoverflow.com/questions/3767328/how-to-perform-a-row-lock but i'm not sure it will work... – Xavinou Mar 09 '12 at 21:16
  • I read that, but it only covers a single statement. How do I ensure that the lock persists through the entire transaction? – Wesley Tansey Mar 09 '12 at 21:18

1 Answers1

0

I don't think it's possible.

sql rowlock on select statement

at work, we do that through a program that runs on the server.

All requests go through this program.

Community
  • 1
  • 1
Xavinou
  • 802
  • 1
  • 6
  • 18