• CELKO (8/12/2012)


    Does an UPDATE query overwrite existing values if the already existing value is the same as the one your updating with?

    Who cares?

    Triggers, for example. transaction logs. Users sitting in frount of the frozen UI waiting while the database finishes the useless activity.

    Update dbo.Event

    SET Status = 1

    WHERE Eventdate < GETDATE()

    and Status = 0

    Without checking for the status value update will take forever on a big history table and add a big chunk to the Transaction Log file.

    If there is a FOR UPDATE trigger it will be executed for all records having Eventdate in the past.

    With Status = 0 added to the query it will actually update only recently added/processed records which have not been updated before. And trigger(s) will be run only for that smaller subset.

    When I fixed similar query on one of production databases it removed 8GB of data added daily to the TRN file. Not to mention easing the pressure on the server, improving performance not only this but other systems having databases hosted on the same SQL Server.

    _____________
    Code for TallyGenerator