Jak zjistit velikost tabule


SELECT 
    OBJECT_NAME(ps.object_id) AS TableName,
    SUM(ps.used_page_count) * 8 AS TableSizeKB,
	SUM(ps.used_page_count) * 8 / 1024 / 1024 AS TableSizeGB,
	SUM(ps.used_page_count) * 8 / 1024 AS TableSizeMB,

    SUM(CASE WHEN i.index_id <= 1 THEN ps.used_page_count ELSE 0 END) * 8 AS DataSizeKB,
	SUM(CASE WHEN i.index_id <= 1 THEN ps.used_page_count ELSE 0 END) * 8 / 1024 AS DataSizeMB,
	SUM(CASE WHEN i.index_id <= 1 THEN ps.used_page_count ELSE 0 END) * 8 / 1024 / 1024 AS DataSizeGB,

    SUM(CASE WHEN i.index_id > 1 THEN ps.used_page_count ELSE 0 END) * 8 AS IndexSizeKB,
	SUM(CASE WHEN i.index_id > 1 THEN ps.used_page_count ELSE 0 END) * 8 / 1024 AS IndexSizeMB,
    SUM(CASE WHEN i.index_id > 1 THEN ps.used_page_count ELSE 0 END) * 8 / 1024 / 1024 AS IndexSizeGB
FROM 
    sys.dm_db_partition_stats ps
INNER JOIN 
    sys.indexes i ON ps.object_id = i.object_id AND ps.index_id = i.index_id
WHERE 
    OBJECTPROPERTY(ps.object_id,'IsUserTable') = 1
	AND OBJECT_NAME(ps.object_id) = 'NazevTabule'
GROUP BY 
    ps.object_id
ORDER BY 
    SUM(ps.used_page_count) DESC;