Solutions for INSERT OR UPDATE on SQL Server

https://stackoverflow.com/questions/108403/solutions-for-insert-or-update-on-sql-server/243670#243670

http://blog.sina.com.cn/s/blog_4f0322c501015jqp.html

MERGE ProjectInfoAppInfoes WITH ( HOLDLOCK ) AS target
USING (
VALUES
( '-1' ,
'-1'
) ) AS source ( ProjectInfo_Id, AppInfo_Id )
ON target.ProjectInfo_Id = 7
WHEN MATCHED THEN
UPDATE SET ProjectInfo_Id = source.ProjectInfo_Id ,
AppInfo_Id = source.AppInfo_Id
WHEN NOT MATCHED THEN
INSERT ( ProjectInfo_Id ,
AppInfo_Id
)
VALUES ( source.ProjectInfo_Id ,
source.AppInfo_Id
);

posted @ 2017-06-01 11:13  天藐水瓶  阅读(360)  评论(0编辑  收藏  举报