IDENTITY_INSERT SQL script

Situation

I have a SQL script that I need to push some underlying data into my database. Therefore I am using the following script (and others). I want to manually provide a primary key for manually generated strings.

Problem

If I run the script, it says I need to enable IDENTITY_INSERT. I added this line SET IDENTITY_INSERT UserGroups ON;

like many examples, but it still gives the same error when I added it.

SET IDENTITY_INSERT UserGroups ON;  
GO 

INSERT INTO UserGroups VALUES (0, 0);

      

Error while running script:

An explicit value for the identity column in the UserGroups table can only be specified when using a list of columns and IDENTITY_INSERT is enabled.

Question

Do I need to change something in my database or is there something else I forgot in the script to manually add the primary key?

More details

I am using SQL Server 2016 Management Studio.

I am using DDL script for SQL scripts

I am working with Entity Framework.

In this table, I got two columns

  • Primary Key: Id
  • int: GroupHeadId
+3


source to share


2 answers


As the error says, you need a list of columns.



INSERT INTO UserGroups (Id, GroupHeadId)
VALUES (0,0)

      

+7


source


The error message reports this problem.

An explicit value for the identity column in the UserGroups table can only be specified if a column list is used and IDENTITY_INSERT is enabled.



You are not using a column list. Specify columns.

+6


source







All Articles