Re: Insert if exists
Declare a primary key/unique key and use REPLACE (http://dev.mysql.com/doc/refman/5.7/en/replace.html) for that same delete-and-insert behavior. But beware of foreign key constraints and cascading deletes if you have any.
If insert-or-update is the desired behavior, then use the INSERT...ON DUPLICATE KEY UPDATE syntax (http://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html) as you were initially. Mind of the primary key/unique key as well.
Regarding your syntax error, after deleting the (!), the only thing I see wrong is the extra closing parenthesis at the end.
Subject
Written By
Posted
Re: Insert if exists
January 04, 2016 04:39AM
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.