0
有沒有辦法避免更新合併語句中「新值」未更改的列?
我仍然需要更新,因爲我需要從輸出子句中插入的表中檢索字段。當然SQL Server:避免在合併中的值更改時更新列
這樣做的目的是避免IO寫
WHEN MATCHED THEN
UPDATE
SET
productName = Src.productName -- Only if Src.productName <> productName
, productNameModel = Src.productNameModel -- Only if Src.productNameModel <> productNameModel
, brandID = Src.brandID -- Only if Src.brandID <> brandID
, ean = Src.ean -- Only if Src.ean <> ean
, categoryID = Src.categoryID -- Only if Src.categoryID <> categoryID
, resellerPrijsEx = Src.resellerPrijsEx -- Only if Src.resellerPrijsEx <> resellerPrijsEx
, inStock = Src.inStock -- Only if Src.inStock <> inStock
, warrantyID = Src.warrantyID -- Only if Src.warrantyID <> warrantyID
, productNamePn = Src.productNamePn -- Only if Src.productNamePn <> productNamePn
OUTPUT Src.ID, inserted.ID, Src.hasDescription INTO @tblID (tmpID, ID, hasDescription) -- Yet UPDATE is required since I need to retrieve inserted ID
;
如果這兩個值是相同的,它會產生什麼不同? – podiluska
我想,這會導致磁盤上無用的寫入(用完全相同的值覆蓋一個值)。 – Serge
你幾乎肯定在想這個。 – podiluska