12/7/2022 4:23:04 AM

SQL

SELECT TableDetails.TableName ,TableDetails.TotalRows ,TableDetails.DiskSpaceInKb ,FORMAT(TableDetails.TotalRows, '###,###,###.##') AS TotalRowsFormatted ,FORMAT(TableDetails.DiskSpaceInKb, '###,###,###.##') AS DiskSpaceInKbFormatted FROM ( SELECT tables.NAME AS TableName, partitions.rows AS TotalRows, DiskSpaceInKb = ( SELECT SUM(allocation_units.total_pages) * 8 FROM sys.allocation_units WHERE sys.allocation_units.container_id = partitions.partition_id ) FROM sys.tables tables INNER JOIN sys.indexes indexes ON tables.OBJECT_ID = indexes.object_id INNER JOIN sys.partitions partitions ON indexes.object_id = partitions.OBJECT_ID AND indexes.index_id = partitions.index_id WHERE partitions.index_id = 1 ) AS TableDetails ORDER BY TotalRows asc ,TableDetails.DiskSpaceInKb asc