I have a table to store int primary keys. Where the value nextID is the value to use.I need to get the value and update it (nextID + 1) before the next person gets it.I thought using tran would work but it doesn't stop a select.How do I get a value (lock the table for the update), update the table (preventing any selects until done) and release the table.[code]BEGIN TRANUPDATE TableIdsSET NextId = NextId + 1WHERE TableName = 'Users'WAITFOR DELAY '00:00:20'SELECT NextIdFROM TableIdsWHERE TableName = 'Users'COMMIT TRAN[/code]I really want to do this in the reverse order but it doesn't work. But if I do this and have another query to just do a select:[code]SELECT NextId FROM TableIdsWHERE TableName = 'Users'[/code]This query never returns. Doesn't the COMMIT TRAN release the lock on the table?Thanks,Tom
↧