There are quite a few questions which cover this error, but I'm having the issue that:
A) I'm currently doing a Merge (with an Insert)
B) I'm not explicitly setting the identity column!
My stored procedure (table names and properties obfuscated):
Table Definition
CREATE TABLE MyTable (
[ID] BIGINT IDENTITY(1, 1) NOT NULL,
[Value] NVARCHAR (256) NOT NULL,
[Property] NVARCHAR (256) NOT NULL,
CONSTRAINT [PK_MyTable] PRIMARY KEY CLUSTERED ([ID] ASC),
CONSTRAINT [IX_MyTable] UNIQUE NONCLUSTERED ([Value] ASC)
);
Stored Procedure Definition
CREATE TYPE TempType as Table (
[TempValue] nvarchar(256) NOT NULL,
[TempProperty] nvarchar(256) NOT NULL,
);
GO
CREATE PROCEDURE [Name]
@Source TempType READONLY
AS
BEGIN
MERGE [MyTable] as target
USING (SELECT * FROM @Source) as source (TempValue, TempProperty)
ON (target.Value = source.TempValue)
WHEN MATCH THEN
UPDATE SET Value = source.TempValue, Property = source.TempProperty
WHEN NOT MATCHED THEN
INSERT ([Value], [Property])
VALUES (source.TempValue, source.TempProperty)
OUTPUT deleted.*, $action, inserted.* INTO [MyTable];
END
From what I can see, I'm not anywhere explicitly specifying the IDENTITY
column. I am specifying a UNIQUE
-ly constrained column though.
Lastly, contrary to what the error says, specifying IDENTITY_INSERT ON
does nothing.
Edit: I should also specify, I'm getting this error while deploying from a .dacpac
via C#.