Heim  >  Artikel  >  Datenbank  >  SQL Server 计算表记录数和占用空间

SQL Server 计算表记录数和占用空间

WBOY
WBOYOriginal
2016-06-07 14:54:571499Durchsuche

无详细内容 无 USE ADVENTUREWORKSGO-- Count All Rows and Size of Table by SQLServerCurry.comSELECTTableName = obj.name,TotalRows = prt.rows,[SpaceUsed(KB)] = SUM(alloc.used_pages)*8FROM sys.objects objJOIN sys.indexes idx on obj.object_id =

USE ADVENTUREWORKS
GO
-- Count All Rows and Size of Table by SQLServerCurry.com
SELECT
TableName = obj.name,
TotalRows = prt.rows,
[SpaceUsed(KB)] = SUM(alloc.used_pages)*8
FROM sys.objects obj
JOIN sys.indexes idx on obj.object_id = idx.object_id
JOIN sys.partitions prt on obj.object_id = prt.object_id
JOIN sys.allocation_units alloc on alloc.container_id = prt.partition_id
WHERE
obj.type = 'U' AND idx.index_id IN (0, 1)
GROUP BY obj.name, prt.rows
ORDER BY TableName
SQL Server 计算表记录数和占用空间
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn