Note: Most of the Article of this blog has taken from another reputated blogs,Websites so Author will not responsible for any Issue.

To Count Records In Tables in sql server 2005,2008

---To Count Records In Tables

Create  PROCEDURE [dbo].[listTableRowCounts]                        

AS                        

BEGIN                        

    SET NOCOUNT ON                        

                        

    DECLARE @SQL VARCHAR(255)                        

    SET @SQL = 'DBCC UPDATEUSAGE (' + DB_NAME() + ')'                        

    EXEC(@SQL)                        

                         

    CREATE TABLE #foo                        

    (                        

        tablename VARCHAR(255),                        

        rc INT                        

    )                        

                            

    INSERT #foo                        

        EXEC sp_msForEachTable                        

            'SELECT PARSENAME(''?'', 1),                 

             COUNT(*) FROM ?'                        

                        

    SELECT tablename, rc                         

        FROM #foo                        

        where rc  > 0  

        Order By tablename                       

                        

    DROP TABLE #foo                        

END