There are two ways to find out the table size;
first option will be to run the system stored procedure “sp_spaceUsed”
1: EXEC sp_SpaceUsed 'table_name'
Option 2 uses the dmv sys.dm_db_partition_stats
1: SELECT t.schema_name + '.' + t.table_name AS table_name2: ,t.index_name3: ,SUM(t.used) AS used_in_kb4: ,SUM(t.reserved) AS reserved_in_kb5: ,SUM(t.tbl_rows) AS rows6: FROM ( SELECT s.Name schema_name7: ,o.Name table_name8: ,COALESCE(i.Name, 'HEAP') index_name9: ,p.used_page_count * 8 used10: ,p.reserved_page_count * 8 reserved11: ,p.row_count ind_rows12: ,CASE WHEN i.index_id IN ( 0, 1 ) THEN p.row_count13: ELSE 014: END tbl_rows15: FROM sys.dm_db_partition_stats p16: INNER JOIN sys.objects AS o ON o.object_id = p.object_id17: INNER JOIN sys.schemas AS s ON s.schema_id = o.schema_id18: LEFT OUTER JOIN sys.indexes AS i ON i.object_id = p.object_id19: AND i.index_id = p.index_id20: WHERE o.type_desc = 'USER_TABLE'21: AND o.is_ms_shipped = 0 ) AS t22: GROUP BY t.schema_name23: ,t.table_name24: ,t.index_name25: ORDER BY 5 DESC26:27:
Post a Comment
Post a Comment