My boss said that DELETE can be an expensive operation, is this true ?
That depends on one's definition of "expensive". I am not aware that a DELETE
is significantly more expensive than an UPDATE
for the same affected records (in fact, it may be cheaper).
Should I put in some logic to figure out what records should be updated and which should be inserted, rather than DELETING and then INSERTING ?
We have no good way of answering that question, because it is largely dependent upon your environment, such as your database schema.
Make sure that you are wrapping these operations in a transaction, as that has a major impact on the speed of bulk operations.
Beyond that, you would need to run some performance benchmarks of your own, to determine how much more expensive DELETE
+INSERT
is over UPDATE
, and therefore whether it is worth the development headache or not to try to switch to an UPDATE
-centric strategy.