MySQL Forums
Forum List  »  General

try UPDATE first, then INSERT if row doesn't exist
Posted by: Chris Bassett
Date: January 06, 2015 10:41AM

Using SQL, how can I go about attempting to update a row first (if it exists) and then resorting to an INSERT if the row doesn't exist?

Some people suggest using MERGE, but I've also read both positive and negative comments regaridng the use of MERGE.

Is there another method, aside from querying each item, and checking to see if each row exists "manually"?

(FYI. I am executing these statements from a C# program so the checking will be done within the program using IF statements to determine if the row exists. If it doesn't, then it performs an INSERT. I'm trying to find an easier way to do this since I technically have about 25 rows to check, and either update or insert).

Options: ReplyQuote


Subject
Written By
Posted
try UPDATE first, then INSERT if row doesn't exist
January 06, 2015 10:41AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.