Overriding unique indexed values

后端 未结 2 783
傲寒
傲寒 2021-01-17 06:47

This is what I\'m doing right now (name is UNIQUE):

SELECT * FROM fruits WHERE name=\'apple\';

Che

相关标签:
2条回答
  • 2021-01-17 07:26

    You can use the IGNORE feature:

    INSERT IGNORE INTO fruits VALUES ('apple')
    

    If there is a key violation, it just skips this value

    0 讨论(0)
  • 2021-01-17 07:49

    check out

    INSERT IGNORE INTO ...
    

    and

    INSERT ON DUPLICATE KEY UPDATE ...
    

    Thes second method is preferred as the IGNORE statement simply causes mysql to issue warning instead of error

    0 讨论(0)
提交回复
热议问题