that it's a physical table or anything.
So, let's say you wanted to 'lock' a customer account while certain
operations were performed on it. You could use the customer's AccountNumber
or CustomerID to lock the entire logical set of operations. So, for customer
The point is, if another user came along to perform the same process, and
lock 'Customer A12345', the lock would be denied if you had an 'Exclusive'
one on it already. Then, when you were finished up, you could release the
lock you had on 'Customer A12345'.
IMO, this is meant to take the place of having kludges like putting a
[RecordLocked] column on your Customer table, and toggling it on/off for
Also, the advantage is that you could apply this so that the customer could
be read, just not edited, etc.. Imagination is the only limit with this new
If you don't see this in BOL, maybe you need to download the latest version.
> Yes, I saw that statement but was not sure what the definition of a
> resource was. Can a resource name be a name of a table ? In your
> example is "Foo #25" a table name ?
> Where did you get the information that this is a "logical" lock. I don't
> see this in the books on line docs.
> > John,
> > I see. There is also the new sp_getapplock and sp_releaseapplock to use
> > just this purpose.
> > (Note: this is a 'logical' lock, it doesn't actually lock the rows in
> > question)
> > Example:
> > /*Lock #25*/
> > EXEC sp_getapplock
> > /*DO WORK*/
> > /*Release #25*/
> > EXEC sp_releaseapplock
> > This has the added advantage of 'locking' the 'virtual resource', but
> > allowing reads on the data in the meantime.
> > James Hokes
> > > James,
> > > Thanks for responding to my message. I assume from your reply that I
> > > don't need to set the TRANSACTION ISOLATION LEVEL.
> > > I am writting a low volumn scheduling program. The tblFoo contains the
> > > list of reservations for time on our instruments (NMR, GC's, etc.). I
> > > want to lock the table while I scan for reservation conflicts. If
> > > are no conflicts then I will make an entry in the table for the
> > > reservation. This will all be done in a stored procedure and should
> > > take up much time. Keep in mind this is a low transaction system.
> > > John
> > > > John,
> > > > TABLOCKX will be held until the end of the transaction.