哪种 SQL 更好?在 MySQL 5.1 上
在 MySQL 中 INSERT
- REPLACE INTO
- INSERT INTO .. ON DUPLICATE KEY UPDATE
哪个 SQL 更好? 你能给我一个建议吗?
In MySQL INSERT
- REPLACE INTO
- INSERT INTO .. ON DUPLICATE KEY UPDATE
Which SQL is Better?
Could you give me a advice?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
取决于你用它们做什么。 REPLACE INTO 从技术上来说更快,因为它不必在更新之前进行读取(但这基本上是无关紧要的),但我觉得 INSERT INTO ... ON DUPLICATE KEY UPDATE 通常更清楚您想要做什么。
这是一个 简短讨论在博客中。
Depends what you're doing with them.
REPLACE INTO
is technically faster since it doesn't have to do a read before updating (but that is mostly irrelevant), but I've felt thatINSERT INTO ... ON DUPLICATE KEY UPDATE
is generally more clear as to what you want to do.Here is a short discussion in a blog.