I would not agree that the basic principle should be applied in this case, since it does some kind of redundant code in your code.
First, let's look at what your UPSERT does, it checks to see if there is data based on whether it performs an INSERT or UPDATE.
In the code for this you need to make 2 calls in your database, depending on how your application is structured, it can also mean opening and closing two connections.
So, you have 3 methods in your code (one for executing each proc), then a method for calling each of these methods and logic to decide if you need to insert or update.
You also have 3 separate stored procedures in your database for each of the actions.
It seems to me that this is poorly structured code, since you would pass the same parameters to your insert / update procedures as you would, and therefore it makes sense to do this all in one place.
Using UPSERT, you have 1 stored procedure and only one connection is required, with one method being called from code. I think this makes a lot better, cleaner code.
source share