Join or subquery in update operations?

Is there any reason to use one of these UPDATE statements over the other in terms of performance?

 UPDATE myTable
 SET    fieldx = 1
 FROM   myTable AS mt
      , myView AS mv
 WHERE  mt.id = mv.id


 UPDATE myTable
 SET    fieldx = 1
 WHERE  id IN ( SELECT id
                     FROM   myView )
+3
source share
2 answers

They will probably come out with the same execution plan, which means there is no difference. To confirm, just try each one in SSMS with the "Enable execution plan" option enabled.

In fact, I would like to:

UPDATE mt
SET mt.fieldx = 1
FROM myTable mt
    JOIN myView mv ON mt.ID = mv.ID

I prefer this syntax. Although, he will also come out with the same execution plan.

, UPDATE. , - :
alt text http://img707.imageshack.us/img707/7801/60422461.png


alt text http://img683.imageshack.us/img683/7874/41210682.png


alt text http://img708.imageshack.us/img708/5020/20506532.png

+5

, , , . , :

UPDATE myTable 
SET    fieldx = 1
--SELECT *
FROM   myTable AS mt 
      , myView AS mv 
WHERE  mt.id = mv.id
0

Source: https://habr.com/ru/post/1731913/


All Articles