我有以下代碼:IDENTITY INSERT不MERGE工作
PRINT N'Merging Wide Format Types...'
SET IDENTITY_INSERT WideFormatTypes ON
GO
MERGE INTO WideFormatTypes AS Target
USING (VALUES
(1, N'****', NULL),
(2, N'****', NULL),
(3, N'******', NULL),
(4, N'*******', NULL),
(5, N'******', NULL),
(6, N'*******', NULL)
)
AS Source (TypeID, TypeName, Description)
ON Target.TypeID = Source.TypeID
WHEN MATCHED THEN
UPDATE SET
TypeID = Source.TypeID,
TypeName = Source.TypeName,
Description = Source.Description
WHEN NOT MATCHED BY TARGET THEN
INSERT (TypeID, TypeName, Description)
VALUES (TypeID, TypeName, Description);
SET IDENTITY_INSERT WideFormatTypes OFF
GO
它返回一個錯誤
消息8102,級別16,狀態1,第1行
無法更新標識列' TYPEID」
表聲明如下:
CREATE TABLE [dbo].[WideFormatTypes]
(
[TypeID] INT IDENTITY (1, 1) NOT NULL,
[TypeName] NVARCHAR (500) NOT NULL,
[Description] NVARCHAR (1000) NULL,
PRIMARY KEY CLUSTERED ([TypeID] ASC)
);
我找不到問題..任何幫助?
感謝您比以前的答案更具描述性!雖然我從那裏得到了相同的信息... – Mortalus