What do you think is better. Update every time all columns of an table even if there are not all values changes, or update only the changed columns with multiple updates. The idea is, rather than to update every single change immediately, waiting for a few changes and then update all columns, but i don't want to implement a logic who determines which columns has been changed.
UPDATE myTable
SET col1 = newVal1,
col2 = oldVal2,
col3 = newVal3,
...
WHERE x = y
vs.
UPDATE myTable SET col1 = newVal1 WHERE x = y
UPDATE myTable SET col3 = newVal3 WHERE x = y
...
I am using SQL Server 2014 Express.
The first query will perform much better because, it just needs to do a single scan/seek
on the table. But in the first query you can update the column which has new values to be updated:
UPDATE myTable
SET col1 = newVal1,
col3 = newVal3,
...
where x = y
But the second query has to scan/seek
the table for each Update
which will take more time than the first query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With