SQL Server:多个查询或 UNION

SQL Server: multiple queries or UNION(SQL Server:多个查询或 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)