Sometimes you will need to change the next identity value of a primary key in SQL Server. It might be because you wiped out the table and want to start counting from one or because you want to force it to start counting from an specific value.
There are two ways to do this. The first one is changing the value through the Microsoft SQL Server Management Studio:
1. Right click the table and select the option to modify the table.
2. Then change the value directly into the editor and save the table modification.
There are two ways to do this. The first one is changing the value through the Microsoft SQL Server Management Studio:
1. Right click the table and select the option to modify the table.

2. Then change the value directly into the editor and save the table modification.

The other option to change the identity value is running the following query:
dbcc checkident('mytablename', reseed, 0)
Where mytablename is the name of the table you want to reseed. The last parameter '0' (zero) is the previous value of the next value you want to create. In this case, the next insert will insert 1 as the primary key. If you use for example 49, the next insert value will be 50.
No comments:
Post a Comment