SQLTeam.com | Weblogs | Forums

DB table count & size



I need to extract the DB table row count and its size up to certain time period. For e.g up to 12.06.2016

The below query will give the figures up to time of the query execution but i need to include the date filter in it. Could any one of you guide me to amend the 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




You'll need to hit the table with COUNT(*) and a WHERE clause. You can't do that with the system data.