I'm trying to run this piece of code:
SET IDENTITY_INSERT [dbo].[FIN_REP_REPORT_LOG] ON
SET IDENTITY_INSERT [dbo].[REPORT_LOG_SEQ] ON
INSERT INTO [dbo].[REPORT_LOG_SEQ] ([sqVal]) VALUES (1000000);
I'm getting this error:

For reference: I'll refer to FIN_REP_REPORT_LOG as 'TABLE A', and REPORT_LOG_SEQ as 'TABLE B'.
The error message after the 2nd IDENTITY_INSERT statement on the REPORT_LOG_SEQ table doesn't even relate!
SET IDENTITY_INSERT [TABLE B] ON
--Msg 8107, Level 16, State 1, Line 1
--IDENTITY_INSERT is already ON for table [TABLE A].
--Cannot perform SET operation for table [TABLE B].
The INSERT INTO statement then fails for [TABLE B]!
INSERT INTO [TABLE B] ([sqVal])
VALUES (1000000)
--Msg 544, Level 16, State 1, Line 1
--Cannot insert explicit value for identity column in table [TABLE B] when IDENTITY_INSERT is set to OFF.
The SET operation on [TABLE B] doesn't happen, so the INSERT operation fails.
What I want to know is:
The scenario:
FYI: Table definition for FIN_REP_REPORT_LOG (TABLE A):
CREATE TABLE [dbo].[FIN_REP_REPORT_LOG](
[ID] [bigint] IDENTITY(1,1) NOT NULL,
[REPORT_NAME] [nvarchar](50) NOT NULL,
[EMPLOYEE_NUMBER] [nvarchar](10) NULL,
[PARAMS] [nvarchar](1000) NULL,
[START_DATE] [datetime2](0) NOT NULL,
[END_DATE] [datetime2](0) NULL
) ON [PRIMARY]
The table definition for REPORT_LOG_SEQ (TABLE B):
CREATE TABLE [dbo].[REPORT_LOG_SEQ](
[sqVal] [bigint] IDENTITY(1000000,1) NOT NULL
) ON [PRIMARY]
Any help (even clues) will be appreciated. :)
From here it say :
IDENTITY_INSERT can only be set to on for one table in a database at a time. It must be turned off, before it can be turned on again for a different table.
1 : It's failing because there is already a table in the database with IDENTITY_INSERT on.
2 : The error state which table has IDENTITY_INSERT already on.
3 : It seem that this code wasn't run at all on dev environment. Try to just run the code bellow in a new query editor in SSMS and see if you get the error. (replace table name)
SET IDENTITY_INSERT [dbo].[Your tableName] ON
SET IDENTITY_INSERT [dbo].[Your tableName2] ON
I believe you will get the error. This should clarify the difference between environment. Don't forget to run the turn off after the test to avoid trouble while debuging.
SET IDENTITY_INSERT [dbo].[Your tableName] OFF
From there you will have to refactor the code to have only one table at the time with IDENTITY_INSERT on.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With