合并与更新插入
我正在使用 SQL Server 后端编写一个应用程序。最常用的部分之一是用户选择问题的答案,然后触发一个存储过程,查看是否已经给出答案,如果有则执行更新,如果没有则执行插入。
这工作得很好,但现在我们已经升级到 SQL Server 2008 Express 我想知道重写此 SP 以使用新的 MERGE 命令是否会更好/更快/更高效。
有谁知道这是否比执行 SELECT 和 INSERT 或 UPDATE 更快?
I have an application I’m writing in access with a SQL server backend. 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.
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.
Does anyone have any idea if this is faster than doing a SELECT followed by either an INSERT or UPDATE?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不值得付出努力。可能是可行的,但它不会给你任何值得注意的东西。
MERGE 特别针对数据仓库,其中找出要插入/更新的内容是棘手的部分。它允许使用一组合并来完成所有操作(插入、更新),而不是针对每个条件执行一个合并。这对您的情况没有真正的影响。
我有一个数据库,我将 3-5 百万行上传到一个 3 亿行的表中 - 合并将我的性能提高了 50%(一次表扫描而不是两次)。
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. 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).