>Hello all, I use a table to keep track of my primary keys. Basically the table contains a field for the tablename and a field for the next available primary key. Is there a way to lock the sql server record until I update it? Also can I run a loop checking the status of the lock so I can grab another lock as soon as the first lock is complete? Thanks for the help.
Randy,
If you are using SQL 2000, do the Read/Increment/Update in one command so the row level locking will keep different users from getting multiples. We have been doing this for a while and no dups yet.
Here is an example:
update sy_uniqueid
set
last_id = last_id + @Increment,
@KeyValue = last_id + @Increment
from
sy_uniqueid
where
tablename = @Name
Of course you will have to declare the variables properly.
BOb