Reset Auto-increment SQL Server

4

Good morning,

I created a new table in SQLServer and I'm testing some scripts to popular the table and I came across the following situation, in my tests I'm doing the insert in the table checking the information and if they do not agree I make a delete in the table , but when I do this the id field that is auto incremental is not zeroing, it is continuing from the id where it stopped, for example: If I include 10 records the auto-incremental id will be at 10 if I make a delete in the records table and do another insert it starts with 11 instead of starting with 1, can anyone help me?

    
asked by anonymous 22.02.2018 / 16:29

1 answer

7

I've simulated your question as follows

  • I made the insert of 83 records in a table

  • Ideletedtherecordsfromthetable

  • IranthecommandtolistatwhichvalueisAUTO_INCREMENTofthetable

    SELECTIDENT_CURRENT('TABELA')

  • Imadeaselecttoshowthatthetableisunregistered

  • Iusedthiscommandwiththetablewithoutrecordstozerooutauto-incremental

    DBCCCHECKIDENT(TABELA,RESEED,0)

  • IlistedwhatcurrentvalueoftheAUTO_INCREMENTofthetableandthesamezerou

  • Alternatively,youcanexecutethiscommandviacmd

    OSQL-E-S<SERVIDOR>-d<BASE>-Q"DBCC CHECKIDENT('<TABELA>', RESEED, 0)"

22.02.2018 / 16:37