Weird error (Msg 8107) on SQL Server 2008 R2 for SET IDENTITY_INSERT -
i'm trying run piece of code:
set identity_insert [dbo].[fin_rep_report_log] on set identity_insert [dbo].[report_log_seq] on insert [dbo].[report_log_seq] ([sqval]) values (1000000);
for reference: i'll refer fin_rep_report_log 'table a', , report_log_seq 'table b'.
the error message after 2nd identity_insert statement on report_log_seq table doesn't relate!
set identity_insert [table b] on --msg 8107, level 16, state 1, line 1 --identity_insert on table [table a]. --cannot perform set operation table [table b].
the insert statement fails [table b]!
insert [table b] ([sqval]) values (1000000) --msg 544, level 16, state 1, line 1 --cannot insert explicit value identity column in table [table b] when identity_insert set off.
the set operation on [table b] doesn't happen, insert operation fails.
what want know is:
- why second set identity_insert statement fail?
- why error message reference unrelated [table a]?
- what can fix it?
the scenario:
- i'm running code 1 line @ time!
- i'm using sql server 2008 r2
- the code works fine in "dev" , "test" servers, fails on production server.
- the 'compatibility level' of production server 100. it's level 80 "dev" , "test" servers.
- their no inter-dependencies between tables in question.
- i not dba. can run code on "dev". dba must run code on "test" , "prod".
- the dba stumped am.
fyi: table definition 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 report_log_seq (table b):
create table [dbo].[report_log_seq]( [sqval] [bigint] identity(1000000,1) not null ) on [primary]
any (even clues) appreciated. :)
from here :
identity_insert can set on 1 table in database @ time. must turned off, before can turned on again different table.
1 : it's failing because there table in database identity_insert on.
2 : error state table has identity_insert on.
3 : seem code wasn't run @ on dev environment. try run code bellow in new query editor in ssms , see if error. (replace table name)
set identity_insert [dbo].[your tablename] on set identity_insert [dbo].[your tablename2] on
i believe error. should clarify difference between environment. don't forget run turn off after test avoid trouble while debuging.
set identity_insert [dbo].[your tablename] off
from there have refactor code have 1 table @ time identity_insert on.
Comments
Post a Comment