Thursday, October 24, 2019

Change IDENTITY_INSERT to ON in SQL server

Explicit identity insert require IDENTITY_INSERT property set to ON.

SET IDENTITY_INSERT MyTable ON  -- Statement Allows explicit values to be inserted into
                                                                     -- the identity column of a table.
GO

INSERT INTO MyTable(ID, Name, Description)
VALUES (0, 'Special title', 'special item');
GO

SET IDENTITY_INSERT MyTable OFF  -- Statement revert granted permission
GO

No comments:

Post a Comment