How to check record existence and insert in MYSQL?

How to check for a record and insert or update in MYSQL?

I have a script that has a set of Insert statements for multiple tables. Now, when I try to execute the Insert statement, I want to do the following:

  • Check for the entry, then insert or update.
  • If the entry does not exist, insert.
  • If the recording is already doing nothing.

How to do it?

Note. script with inserted expressions generated programmatically using SP

+3
source share
2 answers

Use INSERT IGNORE:

INSERT IGNORE INTO table_name
SET column = value
   ...
0
source

This is what mysqls will replace for

http://dev.mysql.com/doc/refman/5.0/en/replace.html

0
source

Source: https://habr.com/ru/post/1744734/


All Articles