sqlserver怎么查看所有表大小

avatar
作者
猴君
阅读量:1

要查看SQL Server中所有表的大小,可以使用以下查询语句:

SELECT      t.NAME AS TableName,     s.NAME AS SchemaName,     p.rows AS RowCounts,     SUM(a.total_pages) * 8 AS TotalSizeKB  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      TotalSizeKB DESC; 

这将返回一个包含所有表的名称、模式、行数和大小(以KB为单位)的结果集。

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!