DBCC CHECKIDENT can reset the identity value of the table. For example, YourTable has 25 rows with 25 as last identity and If we want next record to have identity other than 26.
OR
If you had truncated a table and reloaded, the Identity value will start from the previos value i.e YourTable has 25 rows and you had truncated and reloaded now your identity column values will be from 25 - 50 for the 25 records you inserted.
Run following T SQL script to reset or reseed the identity value of the table:
DBCC CHECKIDENT ("dbo.TableName", RESEED, 1);
If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 1. If identity seed is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error.
OR
If you had truncated a table and reloaded, the Identity value will start from the previos value i.e YourTable has 25 rows and you had truncated and reloaded now your identity column values will be from 25 - 50 for the 25 records you inserted.
Run following T SQL script to reset or reseed the identity value of the table:
DBCC CHECKIDENT ("dbo.TableName", RESEED, 1);
If table has to start with an identity of 1 with the next insert then table should be reseeded with the identity to 1. If identity seed is set below values that currently are in table, it will violate the uniqueness constraint as soon as the values start to duplicate and will generate error.
No comments:
Post a Comment