Wednesday, July 17, 2013

SQL - Record count for all tables in a DB

I needed to count the number of records after a DB backup and restore then the following script helped to do that.
USE [Database_Name] GO CREATE TABLE #tblRecCount ( tblName varchar(255), tblRowCount int ) EXEC sp_MSForEachTable @command1='INSERT #tblRecCount (tblName, tblRowCount) SELECT ''?'', COUNT(*) FROM ?' SELECT tblName, tblRowCount FROM #tblRecCount ORDER BY tblName, tblRowCount DESC SELECT SUM(tblRowCount) AS totalDbRowCount FROM #tblRecCount DROP Table #tblRecCount
The original post is available here.
Share/Bookmark

No comments: