简体   繁体   English

当目标值和源值相同时,合并命令会更新吗?

[英]When target and source values are the same does Merge Command update?

Wasn't really able to find the answer anywhere for this, trying to understand when using the Merge command, if there is a row in my target table that is identical to my source table if it will update the values anyways from the source table.真的无法在任何地方找到答案,试图理解何时使用合并命令,如果我的目标表中有一行与我的源表相同,它是否会更新源表中的值。

In other words I have the following tables:换句话说,我有以下表格:

在此处输入图像描述

Will the source table still run an update on the target table in the above situation?在上述情况下,源表还会对目标表运行更新吗?

What I'm trying to do, if the target table equals source table, do nothing.我正在尝试做的事情,如果目标表等于源表,什么也不做。 Only apply the update/insert/delete functions if there is a true difference between the tables.如果表之间存在真正的差异,则仅应用更新/插入/删除功能。

AND BONUS POINTS, IF POSSIBLE, only run an update on the specific column that is different not the entire row.和奖励积分,如果可能的话,只在特定列上运行更新,而不是整行。

I'm afraid that currently when the "matched" condition is met, it will update the values regardless if they are in fact the same.恐怕目前满足“匹配”条件时,无论它们实际上是否相同,它都会更新这些值。

Now, I understand even if the values are updated they wont be incorrect, but I'm trying to keep track of true adjustments to table via insert/update/delete operations.现在,我明白即使更新了这些值,它们也不会不正确,但我正在尝试通过插入/更新/删除操作来跟踪对表的真实调整。

MERGE target_table USING source_table
ON merge_condition
WHEN MATCHED
    THEN update_statement
WHEN NOT MATCHED
    THEN insert_statement
WHEN NOT MATCHED BY SOURCE
    THEN DELETE;

It appears it still is marked as updated in terms of log activity, but the data itself doesn't update (minus a few situations noted on the link below).就日志活动而言,它似乎仍被标记为已更新,但数据本身并未更新(减去下面链接中提到的一些情况)。 Please see this question on the DBA Stack Exchange请在 DBA Stack Exchange 上查看此问题

DBA StackExchange - Non-Updating Updates DBA StackExchange - 非更新更新

The Impact of Non-Updating Updates不更新更新的影响

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM