Monday, January 5, 2015

Record Count of all table

To get the record count of each table in the database at once.

CREATE TABLE #RecordCount
(
    TableName varchar(500),
    NoOfRows int
)

EXEC sp_MSForEachTable @command1='INSERT #RecordCount(TableName  NoOfRows) SELECT ''?'', COUNT(*) FROM ?'
SELECT TableName NoOfRows  FROM #RecordCount ORDER BY TableName NoOfRows DESC