“INSERT IGNORE” vs “INSERT … ON DUPLICATE KEY UPDATE”

后端 未结 12 2476
孤街浪徒
孤街浪徒 2020-11-21 04:30

While executing an INSERT statement with many rows, I want to skip duplicate entries that would otherwise cause failure. After some research, my options appear

12条回答
  •  被撕碎了的回忆
    2020-11-21 05:14

    Replace Into seems like an option. Or you can check with

    IF NOT EXISTS(QUERY) Then INSERT
    

    This will insert or delete then insert. I tend to go for a IF NOT EXISTS check first.

提交回复
热议问题