Duplicate of "INSERT IGNORE" vs "INSERT ... ON DUPLICATE KEY UPDATE"
Asked
Active
Viewed 62 times
4 Answers
1
INSERT IGNORE INTO `table` VALUES ("val1"), ("abc")
or
INSERT IGNORE INTO `table` SET columnname1="val1"
Karoly Horvath
- 91,854
- 11
- 113
- 173
-
ahh sorry, it's a bit early in the morning *grin* – Karoly Horvath Feb 19 '12 at 10:34
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