sqlserver查询每张表的大小MB
sqlserver查询每张表的大小MB
SELECT t.NAME AS TableName, s.NAME AS SchemaName, p.rows AS RowCounts, SUM(a.total_pages) * 8 /1024 AS TotalSizeMB FROM sys.tables t 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 LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id GROUP BY t.Name, s.Name, p.Rows ORDER BY TotalSizeMB DESC;
查询导出
sqlcmd -S 47.99.32.10 -d LQtex -U webuser -P LQ@2020.com -Q "SELECT t.NAME AS TableName,s.NAME AS SchemaName,p.rows AS RowCounts,SUM(a.total_pages) * 8 /1024 AS TotalSizeMB FROM sys.tables t 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 LEFT OUTER JOIN sys.schemas s ON t.schema_id = s.schema_id GROUP BY t.Name, s.Name, p.Rows ORDER BY TotalSizeMB DESC;" -o lqtex_table_size.csv