0

我有一个场景,我需要用户合并 SQL 语句来同步两个表。假设我有两个表表 A 和表 B。除了表 A 中的一个额外列之外,架构是相同的。那个额外列是一个标志,它告诉我哪些记录已准备好在表 B 中插入/更新。让我们说该标志列是 IsReady。这将是真或假。

我可以在 Merge 语句中使用 Isready=True 还是我需要一个临时表将所有记录从表 A 移动到 IsReady=True 的临时表,然后在 TempTable 和表 B 上使用 Merge SQL?

4

2 回答 2

1

是的,您可以在合并条件中使用该列。

merge tableB targetTable
using tableA sourceTable
on sourceTable.IsReady = 1 and [any other condition]
when not matched then
insert ...
when matched and [...] then
update ...
于 2012-12-17T13:46:46.693 回答
0

这可能会帮助你,

merge into tableB 
using tableA  
on tableB.IsReady=true
when not matched then
insert (tableB.field1,tableB.field2..)
values (tableA.field1,tableA.field2..);
commit;
于 2012-12-17T14:27:12.633 回答