2

Duplicate of "INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"

Community
  • 1
  • 1
user1165454
  • 671
  • 1
  • 6
  • 8

4 Answers4

1
INSERT IGNORE INTO `table` VALUES ("val1"), ("abc")

or

INSERT IGNORE INTO `table` SET columnname1="val1"
Karoly Horvath
  • 91,854
  • 11
  • 113
  • 173
0

Check your table first if the pair of values already exists. If it does simply don't make the insert.

Jan Hančič
  • 51,914
  • 16
  • 93
  • 99
0

three things you can do.

  • You can check before insert if the key pair already exists.
  • Look at INSERT IGNORE syntax
  • You can wrap your code in try catch if you are using PDO to override this error. I personally am not in favor of this but works great
Jaspreet Chahal
  • 2,729
  • 1
  • 14
  • 17
0

You can use INSERT IGNORE. No need to check anything - it brings additional overhead.

Roman Newaza
  • 10,843
  • 10
  • 52
  • 81