Skip to main content
Solved

IDENTITY_INSERT for several tables

  • September 7, 2015
  • 3 replies
  • 83 views

Hi guys,

 

 

I tried using IDENTITY_INSERT on several tables of single SQL Server Non-Spatial writer. There is a error I'm getting that says I cann't do that. I now for the rule that SET IDENTITY INSERT can only be used on a single table per connectio, but I wonder if there is some way to make my 4 tables use this feature with a single writer? These tables aren't beeing populated at same time, so can I do something with SQLExecutor for example or no?

Best answer by takashi

Hi,

 

 

As you mentioned, IDENTITY_INSERT can only be used for a single table per connection. It's a limitation on the Transact-SQL specification.

 

I think the SQLExecutor would be a workaround. e.g.

 

-----

 

FME_SQL_DELIMITER ;

 

SET IDENTITY_INSERT @Value(table_name) ON;

 

@Value(insert_statements);

 

SET IDENTITY_INSERT @Value(table_name) OFF;

 

-----

 

Here, assume that "insert_statements" stores SQL INSERT statements delimited by semi-colon. I think you can create its value with some transformers, e.g. StringConcatenator, Aggregator etc.

 

 

Takashi
This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

3 replies

takashi
Celebrity
  • 7843 replies
  • Best Answer
  • September 8, 2015
Hi,

 

 

As you mentioned, IDENTITY_INSERT can only be used for a single table per connection. It's a limitation on the Transact-SQL specification.

 

I think the SQLExecutor would be a workaround. e.g.

 

-----

 

FME_SQL_DELIMITER ;

 

SET IDENTITY_INSERT @Value(table_name) ON;

 

@Value(insert_statements);

 

SET IDENTITY_INSERT @Value(table_name) OFF;

 

-----

 

Here, assume that "insert_statements" stores SQL INSERT statements delimited by semi-colon. I think you can create its value with some transformers, e.g. StringConcatenator, Aggregator etc.

 

 

Takashi

ascollins1
Contributor
  • Contributor
  • 2 replies
  • January 23, 2023

I think a better workaround is to add each table as a separate writer, rather than constructing insert statements for a SQLExecuter. Looks like both writers can still use the same connection in the same workbench but not attempt IDENTITY_INSERT on two tables in the same writer. The error message is misleading.

It would be great if FME handled this case and we didn't have to use this workaround though please!


evieatsafe
Safer
  • Safer
  • 295 replies
  • January 23, 2023

I think a better workaround is to add each table as a separate writer, rather than constructing insert statements for a SQLExecuter. Looks like both writers can still use the same connection in the same workbench but not attempt IDENTITY_INSERT on two tables in the same writer. The error message is misleading.

It would be great if FME handled this case and we didn't have to use this workaround though please!

Posted an idea, go vote on it for this to be included in future versions! @Andrew Collins​ @aleksandar​