因爲從來沒有人把它作爲真正的答案,Mikael Eriksson在評論中提到的MERGE命令是正確的選擇,它效果很好。
這裏有一個簡單的使用例子:
MERGE dbo.DimProduct AS Target
USING (SELECT ProductID, ProductName, ProductColor, ProductCategory FROM dbo.StagingProduct) AS Source
ON (Target.ProductID = Source.ProductID)
WHEN MATCHED THEN
UPDATE SET Target.ProductName = Source.ProductName
WHEN NOT MATCHED BY TARGET THEN
INSERT (ProductID, ProductName, ProductColor, ProductCategory)
VALUES (Source.ProductID, Source.ProductName, Source.ProductColor, Source.ProductCategory)
OUTPUT $action, Inserted.*, Deleted.*;
來自:http://www.bidn.com/blogs/bretupdegraff/bidn-blog/239/using-the-new-tsql-merge-statement-with-sql-server-2008
這幫助了我。
查看['merge'](http://technet.microsoft.com/en-us/library/bb510625.aspx)。 – 2012-08-09 14:00:20