Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (20.3k points)

Why am I getting an error doing an insert when IDENTITY_INSERT is set to OFF?

How do I turn it on properly in SQL Server 2008? Is it by using SQL Server Management Studio?

I have run this query:

SET IDENTITY_INSERT Database. dbo. Baskets ON

Then I got the message back in the console that the Command(s) completed successfully. However, when I run the application, it still gives me the error shown below:

Cannot insert explicit value for identity column in table 'Baskets' when 

IDENTITY_INSERT is set to OFF.

1 Answer

0 votes
by (40.7k points)

As per MSDN in SQL

SET IDENTITY_INSERT table_with_Identity ONINSERT table_with_Identity (Identity_Column, col2, col3, ...) VALUES (AnIdentity_Value, col1value, col2value, ...)SET IDENTITY_INSERT table_with_Identity OFF

The complete error the message tells that you can’t insert explicit value for identity column in table 'table_with_Identity' when IDENTITY_INSERT is set to OFF.

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Browse Categories

...