Hi Cetin,
I don't think you can't go wrong with either case to be honest.
I only want to make a comment on the implication of the number of operations. Its not that simple I think. An EXISTS command ussually is a very lightweight command because of its nature only to check if an existing record does exist. An update command is a far more resource intensive command (has more implications for handling transactions, isolation, locks, latches etc). Depending on how this implemented on the database side and some database settings, it would not surprise me if the EXISTS strategy is going to be faster and less resource intensive in the end, *if* there are a lot of INSERTS that need to be done.
But for most of us mortal souls, both really are acceptable solutions
Walter,
>>Hi everybody,
>>
>>Just wondering do you agree with the last statement or not in this thread
http://forums.asp.net/t/1368290.aspx ? Does it make sense to do UPDATE first, then INSERT? Or do check first? Or would be no difference here?
>>
>>Thanks in advance.
>
>Nispters' quick solution sample 2 is the worst I have ever seen:) It is a solution w/o thinking. Do not use that one and you could use any way you want:)
>
>I prefer the method posted by the original poster ( update, rowcount = 0 then insert - even in native VFP this was the way I were using). I think it is better than checking for existence first, because:
>
>exits?
> yes - update (total operations 2, exists + update)
> no - insert (total operations 2, exists + insert)
>
>In the other way:
>Update
> ( rowcount is a return value ) = 0?
> no - done (total operations 1 Update)
> yes insert (total operations 2 Update/fail/insert)
>
>PS: However there is another problem that would make this useless and the best way would be to use separate update and insert. Consider you are updating but update fails because of another reason (such as timestamp is your update's part, someone else has changed in between). I don't imply if exists() here but maybe. I know it at client side if I am updating or inserting and be explicit.
>
>Cetin