我需要弄清楚在MS Sql Server FileTable上插入了多少文件及其平均大小。
FileTable已经非常庞大,它可以容纳大约27GB的数据。
这是我正在使用的SQL,但它非常慢。它已经运行了一个多小时,但仍然没有完成。有没有办法加快查询速度?
SELECT round(datalength([file_stream]) / 1048576.0, 2) As FileSizeMB, COUNT(*)
FROM [dbo].[Document] WITH(NOLOCK)
GROUP BY round(datalength([file_stream]) / 1048576.0, 2)
ORDER BY round(datalength([file_stream]) / 1048576.0, 2)
答案 0 :(得分:1)
不确定这是否有效,我没有实现FileTable,但这会得到表的大小。
SELECT
s.Name AS SchemaName,
t.NAME AS TableName,
p.rows AS RowCounts,
SUM(a.total_pages) * 8 AS TotalSpaceKB,
( SUM(a.total_pages) * 8 ) / 1024.0 AS TotalSpaceMB,
(( SUM(a.total_pages) * 8 ) / 1024.0)/1024.0 AS TotalSpaceGB,
SUM(a.used_pages) * 8 AS UsedSpaceKB,
( SUM(a.used_pages) * 8 ) / 1024.0 AS UsedSpaceMB,
(( SUM(a.used_pages) * 8 ) / 1024.0) /1024.0 AS UsedSpaceGB,
( SUM(a.total_pages) - SUM(a.used_pages) ) * 8 AS UnusedSpaceKB,
( ( SUM(a.total_pages) - SUM(a.used_pages) ) * 8 ) / 1024.0 AS UnusedSpaceMB,
(( ( SUM(a.total_pages) - SUM(a.used_pages) ) * 8 ) / 1024.0)/1024.0 AS UnusedSpaceGB,
GROUPING(t.Name)
FROM sys.tables t
INNER JOIN sys.schemas s ON s.schema_id = t.schema_id
INNER JOIN sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN sys.partitions p ON i.object_id = p.OBJECT_ID
AND i.index_id = p.index_id
INNER JOIN sys.allocation_units a ON p.partition_id = a.container_id
WHERE t.NAME NOT LIKE 'dt%'
AND t.is_ms_shipped = 0
AND i.OBJECT_ID > 255
GROUP BY s.Name,
t.Name,
p.Rows
WITH ROLLUP
ORDER BY s.Name,
t.Name