Reset to auto increment

Asked

Viewed 99 times

2

I have a problem at my base of fingers. I have the sending code as auto increment but whenever I delete a sending code the value not reset or I do not restart will always increase. Data table

Table definition

I wanted to know how to reset the number...for example instead of starting at 36 start at 1

  • 1

    This is the expected behavior of 'Auto increment', once initialized will always be (auto) incremented.

  • and there is no way to reset?

1 answer

2

what you can do is use the following command:

DBCC CHECKIDENT

This command checks the current identity value of the specified table and, if necessary, changes the identity value. You can also use DBCC CHECKIDENT to manually set a new current identity value for the identity column.

BCC CHECKIDENT ( table_name [, { NORESEED | { RESEED [, new_reseed_value ] } } ] )

The parameters are:

tablename - It is the name of the table on which to check the current identity value. The specified table must contain an identity column. Table names should be compatible with the rules for identifiers.

NORESEED - Specifies that the current identity value should not be changed.

RESEED - Specifies that the current identity value should be changed.

new_reseed_value - The new value to be used as the current value of the identity column.

For your specific case I believe the command:

DBCC CHECKIDENT ('dbo.envios', RESEED, 1)

Solve the problem.

More information here.

  • and where I put this???

  • Look, I’d have to see your code. It depends a lot on your need.

Browser other questions tagged

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