SQL Server: multiple queries or UNION(SQL Server:多个查询或 UNION)
问题描述
我需要执行 16 个查询.所有这些查询都具有相同的格式:
I've 16 queries that I need to execute. All these queries have the same format :
SELECT string, number, number
将所有这些数据组合在一起对我来说很有意义,因为它可以创建一个包含所有结果的仪表板.
Make sense for me to group all these data together as it's to create a dashboard with all the results.
我的问题是:你认为 UNION ALL
会比一个一个执行所有查询更快吗?
My question is : do you think a UNION ALL
will be faster then executing all the queries one by one?
推荐答案
UNION ALL
当然应该让你更快取回数据.
UNION ALL
should certainly allow you to get the data back faster.
不过,您打算如何处理客户端上的数据?如果您必须将其拆分回 16 组独立的数据集,则整体执行时间可能会增加.
What are you going to do with the data on the client, though? If you have to split it back it into 16 separate sets of data the overall execution time will probably increase.
无论您做什么,您只需要对数据库进行一次调用,因此如果您将其保留为 16 个单独的查询,那么最好在一个 存储过程(或子存储过程)中调用它们程序).
Whatever you do, you only want one call to the database so if you leave it as 16 separate queries then it would be nice to have them all called in one stored procedure (or sub-stored procedures).
这篇关于SQL Server:多个查询或 UNION的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:SQL Server:多个查询或 UNION


基础教程推荐
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01