By Frank Kalis
USE PUBS GO SET NOCOUNT ON CREATE TABLE #TableSpace ( Name char(20) ,RowCnt int ,Reserved varchar(15) ,Data varchar(15) ,Index_Size varchar(15) ,Unused varchar(15) ) DECLARE @Table sysname DECLARE TableCur CURSOR FOR SELECT Table_Name FROM INFORMATION_SCHEMA.Tables WHERE Table_Type = 'BASE TABLE' AND OBJECTPROPERTY(OBJECT_ID(Table_Name),'IsMSShipped') = 0 OPEN TableCur FETCH NEXT FROM TableCur INTO @Table WHILE @@FETCH_STATUS = 0 BEGIN INSERT #TableSpace EXEC sp_spaceused @Table FETCH NEXT FROM TableCur INTO @Table END CLOSE TableCur DEALLOCATE TableCur SELECT * FROM #TableSpace DROP TABLE #TableSpace SET NOCOUNT OFF Name RowCnt Reserved Data Index_Size Unused -------------------- ----------- --------------- --------------- --------------- --------------- __tmpTBLCOL 131 80 KB 16 KB 8 KB 56 KB authors 23 40 KB 8 KB 32 KB 0 KB discounts 3 16 KB 8 KB 8 KB 0 KB dup_authors 40 80 KB 16 KB 8 KB 56 KB employee 43 40 KB 8 KB 32 KB 0 KB jobs 14 24 KB 8 KB 16 KB 0 KB max_t 4 16 KB 8 KB 8 KB 0 KB median 8 16 KB 8 KB 8 KB 0 KB pub_info 8 160 KB 120 KB 16 KB 24 KB publishers 8 24 KB 8 KB 16 KB 0 KB roysched 86 32 KB 8 KB 24 KB 0 KB sales 21 56 KB 8 KB 48 KB 0 KB silly_one 0 0 KB 0 KB 0 KB 0 KB stores 6 24 KB 8 KB 16 KB 0 KB tableCounts 15 16 KB 8 KB 8 KB 0 KB titleauthor 25 56 KB 8 KB 48 KB 0 KB titles 18 40 KB 8 KB 32 KB 0 KB Trace_Table_Name 0 0 KB 0 KB 0 KB 0 KB vals 127 24 KB 8 KB 16 KB 0 KB x 2 16 KB 8 KB 8 KB 0 KB
Danke an Jonathan van Houtte für das Originalskript.
Um sicherzustellen, dass RowCnt aktuell ist, sollte man vorher
DBCC UPDATEUSAGE(0) WITH COUNT_ROWS
ausführen.