SQL SQL查找查询结果的大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4473023/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 08:37:05  来源:igfitidea点击:

SQL Finding the size of query result

sqlsql-servertsql

提问by Spooks

So basically I'm doing a SQL select query, but I want to know how much data I am pulling back (how many kilobytes), any way?

所以基本上我在做一个 SQL 选择查询,但我想知道我正在拉回多少数据(多少千字节),无论如何?

回答by Ta01

Actually, "Show Client Statistics" within SSMS query Editor Window will return the resultset size, Bytes Received from Server, etc

实际上,SSMS 查询编辑器窗口中的“显示客户端统计信息”将返回结果集大小、从服务器接收的字节数等

回答by JNK

SELECT <your query here>
INTO dbo.MyTempTable
FROM <query source>

exec sp_spaceused 'MyTempTable'

DROP TABLE MyTempTable

This wlil Return Rows, Reserved Space, Data space (in KB), Index space, and unused space for that table.

这将返回该表的行数、保留空间、数据空间(以 KB 为单位)、索引空间和未使用的空间。

回答by vlad

You can include the actual execution plan of the query in the Results window of SSMS, which will display an estimated row size for the results. Multiply that by the number of rows to get your result. Not sure how accurate the estimated row size is, though.

您可以在 SSMS 的结果窗口中包含查询的实际执行计划,该窗口将显示结果的估计行大小。将其乘以行数以获得结果。不过,不确定估计的行大小有多准确。

回答by sgriffinusa

You can use sp_spaceused to get the size of a table. But I am unaware of any way to get the size of a query (of course that means little).

您可以使用 sp_spaceused 来获取表的大小。但是我不知道有什么方法可以获取查询的大小(当然这意味着很小)。

One way to get a quick estimate of the size would be to save the data as a text file. Obviously, there will be extra whitespace. But it would give you a general idea on how large the query is.

快速估计大小的一种方法是将数据保存为文本文件。显然,会有额外的空格。但这会让您大致了解查询的大小。