Skip to main content
Inspiring
March 18, 2009
Question

A script - row number

  • March 18, 2009
  • 2 replies
  • 367 views
I need a cf script that finds out the total row count of a sql database...Any idea?
The reason I need is to compare our current db (on SQL05) with the new one that will be attached to the SQL 05....
    This topic has been closed for replies.

    2 replies

    emmim44Author
    Inspiring
    March 18, 2009
    I have found a stored procedure that does what I need... thank you all
    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go


    ALTER 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
    ORDER BY tablename,rc ASC

    DROP TABLE #foo
    END
    Inspiring
    March 18, 2009
    I don't know about a CF script, but a pretty damn simple SQL script is:

    SELECT count(*)
    FROM aTable