All tables' name with record count - SQL Server

Pandians
Posted by Pandians under Sql Server category on | Views : 4759
The following code browse all the TABLEs' name and RECORD Count in the Current Database.
CREATE TABLE #Table_Count
(
TableName VARCHAR(MAX),
RecordCount BIGINT
)
GO
INSERT #Table_Count
EXEC SP_MsForEachTable 'SELECT ''?'', COUNT(1) FROM ?'
GO
SELECT * FROM #Table_Count WHERE RecordCount > 0 ORDER BY RecordCount DESC
GO
DROP TABLE #Table_Count

Cheers

Comments or Responses

Posted by: Raja on: 8/16/2009 Level:Starter | Status: [Member]
Awesome code snippet, I can't believe this code will work. Simply copied and pasted and its working.

Great and thank you very much for sharing.

Take Care.

Login to post response