gpt4 book ai didi

sql-server - 合并声明和身份插入

转载 作者:行者123 更新时间:2023-12-02 00:58:50 26 4
gpt4 key购买 nike

我正在使用 Merge 语句在存储过程中插入/更新数据。

MERGE [dbo].[tReserveData_4541] AS Target
USING (SELECT * FROM [dbo].[tblcangrowhitesh]) AS Source
ON ( [Source].[PK_ID] = [Target].[PK_ID])

WHEN MATCHED THEN
UPDATE SET [Target].[mgender] = Source.[mgender]

WHEN NOT MATCHED BY TARGET THEN
INSERT ([Granularity], [PK_ID], [ROWID],
[mgender], [mma1], [mma2], [mma3],
[mmadmincost], [mmcumulativevolume],
[mmcurrency], [mmdate],
[mmfileimporteddate], [mmfilename])
VALUES ([Source].[Granularity], [Source].[PK_ID], [Source].[ROWID],
[Source].[mgender], [Source].[mma1], [Source].[mma2], [Source].[mma3],
[Source].[mmadmincost], [Source].[mmcumulativevolume],
[Source].[mmcurrency], [Source].[mmdate],
[Source].[mmfileimporteddate], [Source].[mmfilename])

如您所见,我将在 MERGE 语句中插入标识列,即 [PK_ID]。但我做不到。

最佳答案

我不太熟悉 MERGE命令,但是当您直接插入到标识列中时,是否不必使用 IDENTITY_INSERT 命令?例如

SET IDENTITY_INSERT [dbo].[tReserveData_4541] on

MERGE...

SET IDENTITY_INSERT [dbo].[tReserveData_4541] off

关于sql-server - 合并声明和身份插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9635887/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com