语法:
MERGE INTO 表A USING 表B ON 关联条件 WHEN MATCHED THEN 满足执行 WHEN NOT MATCHED THEN 不满足执行
案例:
merge into [dbo].[T_Class_B] using [dbo].[T_Class_A] -- 这里的[dbo].[T_Class_A]也可以是子查询 on [T_Class_A].[ClassName]=[T_Class_B].[ClassName] when matched then update set [T_Class_B].[StudentTotalCount]=[T_Class_A].[StudentTotalCount],[T_Class_B].[Owner]=[T_Class_A].[Owner] when not matched then insert([ClassName],[StudentTotalCount],[Owner]) values([T_Class_A].[ClassName],[T_Class_A].[StudentTotalCount],[T_Class_A].[Owner]);
结果:
标签:同步,dbo,INTO,ClassName,MERGE,StudentTotalCount,Owner,Class From: https://www.cnblogs.com/FanJunCheng521/p/17168104.html