ID of out-of-order tables

Asked

Viewed 139 times

2

I have a table with 9 records, my identities are in order from 1 to 9, when I enter a new record in the table automatically a new ID is set, but it is set with the value 30 instead of the next number that in this case would be 10 ( I have 9 records). If by chance I enter records their ID passes following the order is 31, 32, 33...

I don’t know how to fix this problem.

  • Good you had entered some data and then removed them right ?

  • Yes...I entered some data and then deleted it...

  • So master responded to your need see if it helps you

1 answer

2


Using the command below you will be resetting the autoincrement arriving at what you need:

DBCC CHECKIDENT (minhaTabela, RESEED, 10)

Or to ensure that there are no flaws:

declare @max int;  
select @max = max(key) from minhaTabela;  
dbcc checkident(minhaTabela,reseed,@max)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.