SQLServer lock table during stored procedure
问题 I've got a table where I need to auto-assign an ID 99% of the time (the other 1% rules out using an identity column it seems). So I've got a stored procedure to get next ID along the following lines: select @nextid = lastid+1 from last_auto_id check next available id in the table... update last_auto_id set lastid = @nextid Where the check has to check if users have manually used the IDs and find the next unused ID. It works fine when I call it serially, returning 1, 2, 3 ... What I need to do