In SQL Server 2012, the following query is seeding the identity column myTable_id
from 2 instead of 1. Why? myTable_id
is also PK.
DELETE FROM myTable;
GO
SELECT * FROM myTable --0 rows are returned as expected
GO
DBCC CHECKIDENT(myTable, RESEED,1)
GO
INSERT INTO myTable(col1,col2,col3) SELECT FROM AnotherTable(col1,col2,col3)
GO
SELECT * FROM myTable --1005 rows are returned as expected, but identity value starts from 2
GO
Remark:
- The data inserted is right, the only issue is that the newly inserted data starts from 2 instead of 1.
- In the above sql code if I use
DBCC CHECKIDENT(myTable, RESEED,0)
the identity column correctly starts from 1. - Following is snapshot in SSMS for the
myTable_id
column: