MySQL Forums
Forum List  »  Newbie

Re: Insert if not exists MYSQL 5.5.24
Posted by: Colleen Boye
Date: June 07, 2013 03:02PM

So you want to insert this line iff a line with cod=1 doesn't already exist?

If cod is your primary key, just use INSERT IGNORE. Then it will try to insert the line, and if a line with the same primary key already exists, it won't insert it.

If cod isn't your primary key...well, I'd seriously think about making it a primary key, since you're basically using it as one already (ie, creating records that should have distinct values in that field).

Options: ReplyQuote


Subject
Written By
Posted
Re: Insert if not exists MYSQL 5.5.24
June 07, 2013 03:02PM


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.