I have a query which will show the Table Name, Number of Rows and Size of the record of a Database tables in SQL Server. when I executed the query I got a result showing
TableName NumberOfRows SizeinKB
TBL_PROCESS_AUDIT2 1 16
But When I inserted more record into the same table using the same insert query and executed the query, it showing more number of rows (50) but the same size (16kb).
TableName NumberOfRows SizeinKB
TBL_PROCESS_AUDIT2 50 16
Actually when the number of rows of a table is increasing, it's size also should increase. So for 1 record the size is 16KB so for 50 records, the size should be 800KB. When I inserted bulk record like some 2000 records, the size is varying.
What would be the logic or problem in my query? I want the actual size of the records of a DB table.
My Query:
CREATE TABLE #RowCountsAndSizes (TableName NVARCHAR(128),rows CHAR(11),
reserved VARCHAR(18),data VARCHAR(18),index_size VARCHAR(18),
unused VARCHAR(18))
EXEC sp_MSForEachTable 'INSERT INTO #RowCountsAndSizes EXEC sp_spaceused ''?'' '
SELECT TableName,CONVERT(bigint,rows) AS NumberOfRows,
CONVERT(bigint,left(reserved,len(reserved)-3)) AS SizeinKB
FROM #RowCountsAndSizes
ORDER BY NumberOfRows DESC,SizeinKB DESC,TableName
DROP TABLE #RowCountsAndSizes