My requirement is to fetch a unique ID from the database for processing on the application server(clustered application).For this , I have a table with single cell, holding a value X. This value will be incremented everytime it is fetched.
BEGIN TRAN
UPDATE ID_TABLE SET VALUE = VALUE + 1
SELECT VALUE FROM ID_TABLE
END TRAN
Consider a schedule of two transcations(T1 & T2) occurring as follows. UPDATE(T1) , UPDATE(T2) , READ(T1), READ(T2)
Is such interleaving possible , for database transactions.
Are there any ways to avoid this apart from acquiring a lock on the table, in the beginning, and releasing it in the end, which will isolate the transaction?