Skip to content

Instantly share code, notes, and snippets.

@DevDengChao
Created March 23, 2018 16:38
Show Gist options
  • Save DevDengChao/c260d3493cd227c9f9741bb0f1182cdc to your computer and use it in GitHub Desktop.
Save DevDengChao/c260d3493cd227c9f9741bb0f1182cdc to your computer and use it in GitHub Desktop.
MySQL 规避数据重复: + 插入数据时可以通过 `IGNORE` 来忽略当前插入的内容. + `REPLACE INTO` 则是将旧数据清除, 插入新数据进行替换. + 如果在 `REPLACE INTO` 的过程中出现了主键冲突或独特性冲突, 则可以使用 `ON DUPLICATE KEY UPDATE` 更新已有的数据.
INSERT IGNORE authorities (create_date, created_by, enabled, last_modified_by, last_modified_date, authority)
VALUES (current_date(), 'Init', TRUE, 'Init', current_date(), 'USER')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment