Run the following script that creates and populates the table in your dev database.
SET NOCOUNT ON Drop Table dbo.Region GO CREATE TABLE dbo.Region( RegionId int IDENTITY(1,1), RegionName varchar(100) NOT NULL ) GO INSERT INTO dbo.Region (RegionName) VALUES ('Region One'), ('Region Two'); GO SELECT * FROM dbo.Region
The result of this is what you expect from a good Identity field behavior.
RegionId RegionName ----------- ------------------ 1 Region One 2 Region Two
Now add a couple of values ββto the Identity column.
SET NOCOUNT ON Drop Table dbo.Region GO CREATE TABLE dbo.Region( RegionId int IDENTITY(1,1), RegionName varchar(100) NOT NULL ) GO SET IDENTITY_INSERT dbo.Region ON; INSERT INTO dbo.Region (RegionId, RegionName) VALUES (-9, 'Unknown'), (-99, 'N/A'); SET IDENTITY_INSERT dbo.Region OFF; INSERT INTO dbo.Region (RegionName) VALUES ('Region One'), ('Region Two'); GO SELECT * FROM dbo.Region
Output signal
RegionId RegionName
Where is RegionId = 1 go?
Change For further research, Sql-Server does not skip everything if you try to perform the same trick twice
SET NOCOUNT ON Drop Table dbo.Region GO CREATE TABLE dbo.Region( RegionId int IDENTITY(1,1), RegionName varchar(100) NOT NULL ) GO SET IDENTITY_INSERT dbo.Region ON; INSERT INTO dbo.Region (RegionId, RegionName) VALUES (-9, 'Unknown'), (-99, 'N/A'); SET IDENTITY_INSERT dbo.Region OFF; INSERT INTO dbo.Region (RegionName) VALUES ('Region One'), ('Region Two'); GO SET IDENTITY_INSERT dbo.Region ON; INSERT INTO dbo.Region (RegionId, RegionName) VALUES (-999, 'Known-Unknown'), (-9999, 'Really N/A'); SET IDENTITY_INSERT dbo.Region OFF; INSERT INTO dbo.Region (RegionName) VALUES ('Region Four'), ('Region Five'); GO SELECT * FROM dbo.Region
Result here
RegionId RegionName
In the previous case, 1 lost. Here 4 not missing!
So now this is an unpredictable, missing person!
Why could not I miss RegionId = 1 , but RegionId = 4 will not disappear ?!