Re: Insert if exists
Posted by: Filipe Silva
Date: January 04, 2016 04:39AM

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.

Options: ReplyQuote


Subject
Written By
Posted
January 03, 2016 07:50AM
January 03, 2016 12:46PM
January 04, 2016 03:29AM
January 04, 2016 03:52AM
Re: Insert if exists
January 04, 2016 04:39AM
January 18, 2016 05:44PM


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.