0
我有這樣的遺留代碼...合併:如果我用delete/insert替換合併,問題出在哪裏?
MERGE [Salesforce_Lead] AS target
using (
SELECT lead_id,
salesforce_id,
createdbyid,
email,
updatedate
FROM Source.Leads) AS source
ON (
target.lead_id = source.lead_id)
WHEN matched
AND Checksum(target.lead_id, target.salesforce_id) <> Checksum(source.lead_id,source.salesforce_id)
OR Checksum(target.lead_id, target.createdbyid) <> Checksum(source.lead_id,source.createdbyid)
OR Checksum(target.lead_id, target.email) <> Checksum(source.lead_id,source.email)
OR Checksum(target.lead_id, target.updatedate) <> Checksum(source.lead_id,source.updatedate)
THEN
UPDATE
SET target.salesforce_id = source.salesforce_id,
target.createdbyid = source.createdbyid,
target.email = source.email,
target.updatedate = source.updatedate,
when not matched BY target THEN
INSERT
(
lead_id,
salesforce_id,
createdbyid,
email,
updatedate,
)
VALUES
(
source.lead_id,
source.salesforce_id,
source.createdbyid,
source.email,
source.updatedate
)
而且我想改變它下面的代碼:
DELETE FROM [dbo].[Salesforce_Lead]
FROM [dbo].[Salesforce_Lead] AS L
INNER JOIN Source.Leads AS t
ON L.lead_id = t.lead_id;
INSERT INTO [dbo].[lead]
SELECT *
FROM Source.Leads
原因: - 較短的代碼,更易於維護。 - 我以爲如果你是從源代碼刪除,或者使用OUTPUT子句,MERGE應該被使用...... - 沒有太多的更新,通常是一個普通的插入。
我錯過了什麼?我通過「匹配時」獲得的表現是我應該使用MERGE的唯一原因,但正如我所說的,其中大部分都是插入。如果我用delete/insert替換merge,是否有任何問題?