Thursday, January 17, 2019

[SSMS] Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF



Server: Msg 544, Level 16, State 1, Line 1 Cannot insert explicit value for identity column in table when IDENTITY_INSERT is set to OFF. 



 
SET IDENTITY_INSERT [AllAppsUITest].[dbo].[TestEnvironment] ON


Then Insert

 
/* Turn Identity Insert ON so records can be inserted in the Identity Column  */
SET IDENTITY_INSERT [dbo].[TableName] ON
GO
INSERT INTO [dbo].[TableName] ( [ID], [Name] )
VALUES ( 2, 'InsertName')
GO
/* Turn Identity Insert OFF  */
SET IDENTITY_INSERT [dbo].[TableName] OFF
GO

No comments:

Post a Comment