views:

40

answers:

1

I'm updating a table from another table in the same database - what would be the best way to count the updates/inserts?

I can think of a couple of methods:

  1. Join the tables and count (i.e. inner join for update, left join where null for inserts) then perform the update/insert

  2. Use the modification date in the target table (this is maintained correctly) and do a count where the mod date has change, this would have to be done after the update, and before and after the insert... sure you get the idea.

Currently I use method two as I thought it may be faster not having to join the tables, and the modification time stamp data is there anyway.

What are peoples thoughts on this? (I wanted to tag this best-practice, but that tag seems to have disappeared).

EDITED: Sorry, I should have been more specific to the scenario - assume only one concurrent update (this is to update an archive/warehouse overnight) and the provider for SSIS were using won't return the number of rows updated.

A: 

I'd probably keep using the second option. If you know you're running daily (or any other regular interval), you could just test for all modifications (updates and inserts) based on the datepart / day (depending on interval) value in your timestamp column.

This way you'll not have to rewrite your update-testing procedure when your inserts/joins/other requirements change.

(Of course, you're vulnerable to changes by other agents).

You could also introduce a 'helper column' where you set a unique update value, but that smells fishy.

Tobiasopdenbrouw
I don't like fish. ;) no one else has permission to write to this db, so should be safe.
Mr Shoubs