In a nutshell – update only where needed. If you want more in-depth, proceed to read.
I recently had a DBA send me an email on how one of the stored procedures I maintain is bad; In my defense, I didn’t write it, I just maintain it. Another quick side note, I don’t find this to be a “omfg you serious?!” moment when DBAs explain things to me; I think it’s a great learning opportunity.
Anyway, the query was bad because it updated multiple fields when it really didn’t need to. This leads to an unnecessary increase of write I/O on the server. You may be thinking “well duh, it’s so obvious” while reading or after the examples, but I figured why not blog about it. Let’s get to the examples:
So we have two tables; tblCustomers that belong to the system and tblStageCustomers to hold customers coming into the system. The first example is just showing a simple way to help decrease the write I/O. The second example shows how we want to ensure we must have some change prior to updating. Hopefully it’s simple enough to understand.