SQL Server合并语句,其中两个表为Target

时间:2016-03-16 11:04:07

标签: sql sql-server merge

是否可以在SQL合并语句中使用两个表作为目标? 目前我正在使用结构:

    MERGE table_name1 as Target
    USING 
------

但我需要及时处理2个表:

类似的东西:

  MERGE table_name1, table_name2 as Target
    USING 

当前结构(我不能将表2描述为目标):

MERGE table1 as Target

USING 
(
DATASOURCE
) 
as Source

ON 
              Target.id = Source.id

WHEN NOT MATCHED BY TARGET THEN

INSERT VALUES INTO TABLE1
THEN  GET ID FROM TABLE1
INSERT VALUES, ID INTO TABLE 2



WHEN MATCHED AND EXISTS
(

SELECT 


SOURCE.column

EXCEPT

SELECT

Target.column
)
THEN 
UPDATE
    SET
Target.name1 = Source.name1
;

0 个答案:

没有答案