I have an application for display token queues in hospitals/similar institutes. It issues department wise token numbers for the visitors. For this we have the below table which has the last issued token no.
HospId Int Not Null
DeptId Int Not Null
TokenId Int Not Null /* current token number */
While issuing the token I execute the following update statement
Update <table> Set TokenId = (Select Max(TokenId) + 1 From <table>)
Where HospId = @HospId And DeptId = @DeptID
This is working fine, but when there are more concurrent users (more than 200 users) updating the token it gets hang. Is there a better way to update?