美文网首页
SQLServer MERGE INTO

SQLServer MERGE INTO

作者: DH东海 | 来源:发表于2019-03-25 13:58 被阅读0次
MERGE INTO @TargetTable AS T           
USING @SourceTable AS S                
   ON T.ID = S.ID                      
WHEN MATCHED         
   THEN UPDATE SET T.DSPT = S.DSPT  
WHEN NOT MATCHED BY TARGET   
   THEN INSERT VALUES(S.ID,S.DSPT)
WHEN NOT MATCHED BY SOURCE            
   THEN DELETE
OUTPUT $ACTION AS [ACTION],
   Deleted.ID AS 'Deleted ID',
   Deleted.DSPT AS 'Deleted Description',
   Inserted.ID AS 'Inserted ID',
   Inserted.DSPT AS 'Inserted Description'
INTO @Log;

相关文章

网友评论

      本文标题:SQLServer MERGE INTO

      本文链接:https://www.haomeiwen.com/subject/libvvqtx.html