我正在尝试在具有标识列的表中插入记录。由于各种原因,这不应该是直接插入,而是应该与外表具有相同的 ID。所以我跑:
EXECUTE ('SET IDENTITY_INSERT RemoteDB.dbo.FrameContent ON')
INSERT INTO [RemoteDB].[dbo].[FrameContent] ([ID],[FrameID],[PacketType])
SELECT [ID],[FrameID],[PacketType]
FROM FrameContent
WHERE [ID] NOT IN (SELECT [ID] FROM [RemoteDB].[dbo].[FrameContent])
我得到了错误:
Cannot insert explicit value for identity column in table 'FrameContent' when IDENTITY_INSERT is set to OFF.
有任何想法吗?它抱怨 IDENTITY_INSERT 不应该关闭,但我将其设置为开启。