--WHEN NOT MATCHED BY Source 和WHEN NOT MATCHED BY TARGET 是固定格式
--用USING中查到的数据S 对T表来操作
MERGE INTO [Admin] T
USING Admin2 AS S
ON ( T.LoginId = S.LoId )
WHEN NOT MATCHED BY TARGET THEN --目标表(T)中不存在 源表(S)中存在
INSERT (LoginId ,LoginPwd )
VALUES (s.loid ,s.lopwd);
go
MERGE INTO [Admin] T
USING Admin2 AS S
ON ( T.LoginId = S.LoId )
WHEN NOT MATCHED THEN --目标表(T)中不存在 源表(S)中存在
INSERT (LoginId ,LoginPwd )
VALUES (s.loid ,s.lopwd);
go
MERGE INTO [Admin] T
USING Admin2 AS S
ON ( T.LoginId = S.LoId )
WHEN NOT MATCHED BY Source THEN --目标表(T)中存在 源表(S)中不存在
delete;
go
WHEN MATCHED 是当上面条件成立 执行下面操作
WHEN MATCHED 后面可以跟 and
WHEN NOT MATCHED BY Source 和 WHEN NOT MATCHED BY TARGET 是固定格式
WHEN NOT MATCHED BY TARGET 和 WHEN NOT MATCHED 相同
用Using中查到的数据S 对 T操作