all groups > sql server programming > december 2006 >
You're in the

sql server programming

group:

Notification of row locking in case of concurrent updates


Notification of row locking in case of concurrent updates Shocky
12/11/2006 9:55:30 PM
sql server programming: When concurrent updates happen to a row of a table in SQL Server 2000,
one user should be notified that row is already locked by some other
user.

Can this be done? How?
Re: Notification of row locking in case of concurrent updates Erland Sommarskog
12/12/2006 12:00:00 AM
Shocky (yusuf.bhiwandiwala@gmail.com) writes:
[quoted text, click to view]

The best mechanism is to use a timestamp column. A timestamp column is
updated each time a row is updated. The value is unique database-wide, and
monotonically increasing 8-byte value, unrelated to date and time.

When you get a row to the client you also retrieve the timestamp value.
When you update the row, you do something like this:

UPDATE tbl
SET ...
WHERE keycol = @keycol
AND tstamp = @tstamp
IF @@rowcount = 0
RAISERROR('The row has been updated by another user.', 16, 1)



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
AddThis Social Bookmark Button