List:General Discussion« Previous MessageNext Message »
From:Vivek Khera Date:November 1 1999 6:07pm
Subject:Re: if exists UPDATE else INSERT
View as plain text  
>>>>> "SH" == Scott Hess <scott@stripped> writes:

SH> As a backup for REPLACE in such cases, I use UPDATE, look at the affected
SH> rows value, and if no rows were affected, followup with INSERT (there's a
SH> race condition if someone else is in the same code - if the INSERT fails,
SH> try another UPDATE).  This is tuned for cases where UPDATE is the norm,

If you try the INSERT first, then there's no race condition, provided
you have the necessary info to insert all the fields of the PRIMARY
KEY (or all UNIQUE keys).  Other than that, you'll need to do a lock.

Personally, I find REPLACE useless unless you're inserting all the
if exists UPDATE else INSERTErik Andersson30 Oct
  • Re: if exists UPDATE else INSERTJim Faucette30 Oct
  • Re: if exists UPDATE else INSERTScott Hess1 Nov
    • Re: if exists UPDATE else INSERTVivek Khera1 Nov
  • Re: if exists UPDATE else INSERTScott Hess2 Nov