Alex Rivera | Logout

SQL Server performance - IF Select + Update vs Update

Asked 2012-05-31T09:20:57.477
8

I'm writing a big script, full of update statements that will run daily. Some of this updates will affect rows others won't.

I believe that update statements that won't affect anything is not very good practice, but my question is:

  • How badly can this affect performance?? Is this very different from having select statements and update only when select fetches something?

Thank you, Tiago

Edit
Report

1 Answer

1

It depends how you're doing the update. If you're updating using the joined syntax (i.e.)

UPDATE targetTable
FROM targetTable INNER JOIN sourceTable

Then you can pretty simply add WHERE clauses to only update the row if the values you want to set are actually different.

And yes, it can affect performance, particularly if you consider that something like this...

UPDATE targetTable SET column = column

...would fire a trigger that was defined on UPDATE. I'm not 100% on this, but I believe this also does then make it into the transaction log because it needs to be maintained in order for log tail backups and mirroring targets to be able to fully piece together the sequence of events.

answered 2012-05-31T10:49:05.300

Your Answer