简体   繁体   English

哪些SQL UPDATE语句会更快?

[英]Which of these SQL UPDATE statements would be faster?

Which would be faster? 哪个会更快?

Method A: 方法A:

UPDATE table1
SET table1.column1 = table2.column1 
FROM table2
WHERE table1.column2 = table2.column2

Method B: 方法B:

UPDATE table1
SET table1.column1 = table2.column1 
FROM table1
JOIN table2 on table1.column2 = table2.column2

Will they generate the same execution plan? 他们会生成相同的执行计划吗?

Is there any case where I should avoid one of them? 有什么情况我应该避免其中一个吗?

Some tests I did took them almost the same time to execute, but always good to hear a second opnion. 我做过的一些测试几乎同时执行它们,但总是很高兴听到第二个意见。

They are equivalent. 它们是等价的。 You can verify this by checking the execution plan yourself. 您可以通过自己检查执行计划来验证这一点。 The second option: 第二种选择:

UPDATE table1
SET table1.column1 = table2.column1
FROM table1 JOIN
     table2 on table1.column2 = table2.column2

Is currently the preferred method for writing queries, as it's more clear why the criteria is being specified. 目前是编写查询的首选方法,因为更清楚的是为什么要指定标准。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM