Will SQL update the record if the new values โ€‹โ€‹match?

Will SQL update the record if there are no changes to the record?

For reference, is it more efficient to replace

UPDATE TABLE myTable Set Col1 = ISNULL(Col1,'') ... Set Col100 = ISNULL(Col30,'') 

from

 UPDATE TABLE myTable Set Col1 = ISNULL(Col1,'') ... Set Col100 = ISNULL(Col30,'') WHERE Col1 IS NULL OR ... Col30 IS NULL 
+6
source share
2 answers

Yes, he will try to rewrite.

+5
source

You must manage it manually, in the where clause you can put all the fields if they differ from the new values, and where the identifier of your table is equal to your parameter, you will make sure that only the changed records will be updated.

  UPDATE table SET field1 = @field1, field2 = @field2 WHERE field1 != @field1 AND field2 != @field2 AND id = @id 
+1
source

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


All Articles