問題描述
我需要執行 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!