我正在尝试使用merge语句通过连接另外两个表来更新一个表。我写的更新语句非常慢,所以我想用合并替换它。这是剧本给我带来的问题。
UPDATE T1
SET TitleID = T2.TitleID
FROM Customer T1
INNER JOIN Customer_Temp T3
on T1.importFK = T3.importFK
INNER JOIN Customer_Title T2
on T2.TitleDescription = T3.TitleDescription
and T2.ID = @ID
答案 0 :(得分:2)
MERGE
可能不会提高性能。对于此查询:
UPDATE T1
SET TitleID = T2.TitleID
FROM Customer T1 INNER JOIN
Customer_Temp T3
ON T1.importFK = T3.importFK INNER JOIN
Customer_Title T2
ON T2.TitleDescription = T3.TitleDescription AND T2.ID = @ID;
你想要索引。我建议:
Customer_Title(ID, TitleDescription, TitleId)
Customer_Temp(TitleDescription, importFK)
Customer(importFK)