简体   繁体   English

MERGE与UPSERT

[英]MERGE vs. UPSERT

I have an application I'm writing in access with a SQL server backend. 我有一个应用程序,我正在访问SQL服务器后端。 One of the most heavily used parts is where the users selects an answer to a question, a stored procedure is then fired which sees if an answer has already been given, if it has an UPDATE is executed, if not an INSERT is executed. 使用最频繁的部分之一是用户选择问题的答案,然后触发存储过程,查看是否已经给出答案,是否执行了UPDATE,如果没有执行INSERT。

This works just fine but now we have upgraded to SQL server 2008 express I was wondering if it would be better/quicker/more efficient to rewrite this SP to use the new MERGE command. 这工作得很好,但现在我们已升级到SQL server 2008 express我想知道重写此SP以使用新的MERGE命令是否会更好/更快/更有效。

Does anyone have any idea if this is faster than doing a SELECT followed by either an INSERT or UPDATE? 有没有人知道这是否比执行SELECT后跟INSERT或UPDATE更快?

Not worth the effort. 不值得努力。 Possibly doable, but it will not give you anything noticable. 可能是可行的,但它不会给你任何明显的东西。

MERGE is especially targeting data warehouses where finding out what to insert/update is the tricky part. MERGE特别针对数据仓库,其中找出插入/更新的内容是棘手的部分。 It allows all operations (insert, update) to be done with ONE set of merges, compared to one for each condition. 它允许所有操作(插入,更新)使用一组合并完成,而每个条件使用一个合并。 This makes no real difference in your case. 这对你的情况没有任何实际意义。

I have one database where I am uploading 3-5 million rows into a 300 million row table - there merge improoves my performance by 50% (one table scan instead of two). 我有一个数据库,我将300万行上传到3亿行表中 - 合并使我的性能提高了50%(一次扫描而不是两次)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM