SSDT-DevPack icon indicating copy to clipboard operation
SSDT-DevPack copied to clipboard

MergeUI does not include SET IDENTITY_INSERT <tablename> ON prior to MERGE statements that perform INSERTs

Open lestephane opened this issue 7 years ago • 0 comments

When I use MergeUI to generate insert + update + delete statements, and the table I generate the statement for has an IDENTITY column, I get a MERGE statement that contains an INSERT

WHEN NOT MATCHED BY TARGET THEN INSERT ([id],...

But here id is an IDENTITY column, so that fails with the error:

[S0001][544] Cannot insert explicit value for identity column in table '<tablename>' when IDENTITY_INSERT is set to OFF.

I could surround the MERGE statement with the statement to allow INSERTs

SET IDENTITY_INSERT <tablename> ON
<MERGE statement>
SET IDENTITY_INSERT <tablename> OFF

But that somehow feels wrong, since the tool itself knows already that it has to generate inserts. I think MergeUI itself should surround SET IDENTITY_INSERT.

lestephane avatar Feb 07 '18 13:02 lestephane