ID of tables out of order

2

I have a table with 9 records, my identities are in the order of 1 to 9, when I insert a new record in the table automatically a new ID is set, but it is set to the value 30 instead of with the next number which in this case would be 10 (I have 9 records). If by chance I am inserting records the ID of them goes on to follow the order is stand 31, 32, 33 ...

I do not know how to fix this problem.

    
asked by anonymous 10.08.2017 / 14:33

1 answer

2

Using the command below you will be resetting the autoincrement by getting what you need:

DBCC CHECKIDENT (minhaTabela, RESEED, 10)

Or to make sure you have no flaws:

declare @max int;  
select @max = max(key) from minhaTabela;  
dbcc checkident(minhaTabela,reseed,@max)
    
10.08.2017 / 14:59