Set IDENTITY_INSERT on and off in SQL Server:
Execute INSERT Database Insert data times the following error, I clearly did not give the primary key set value but still error
Here's how to fix it:
Qlserver when you insert a record in bulk, set the SET IDENTITY_INSERT table name on the field that has the identity column, and then perform the insert record operation; revert to off setting after insert is complete
Format:
SET IDENTITY_INSERT table name on
SET IDENTITY_INSERT table name off
Example:
SET Identity_insert Peoplepworkpositiontype on
Insert Peoplepworkpositiontype (Id,workpositiontype,workpositiontypeid) VALUES (1, ' Platform ', 1)
Insert Peoplepworkpositiontype (Id,workpositiontype,workpositiontypeid) VALUES (2, ' Land ', 2)
Insert Peoplepworkpositiontype (Id,workpositiontype,workpositiontypeid) VALUES (3, ' Sea ', 3)
Setting method for set IDENTITY_INSERT on and off in SQL Server