I have a primary key on a table in SQL Server (I'm using version 9.00.4060.00 SP3 Standard Edition).
Let's say it has values 1,2,3,5,17 in it.
I could cycle through each row in order until I found a missing value (4 in this case) which is fine if the number of rows is small, but if there are millions of rows and the first missing number is in the middle this will take ages.
Is there some SQL Server built-in functionality for doing this quickly?