# Records in Table BY Table Entire database

  • How would I do this in a stored procedure?

    SELECT COUNT (*), TableName

    FROM DATABASE LotsOfTables.MDF

     

    I have a database that I'm reviewing that has about 400 tables, but my guess is 20 are used, LOL.  I'd like to use Query Analyzer to get the TableName and Count.  Thanks

     

  • Here is an easy way to do it:

    sp_msforeachtable @command1= 'print ''?''', @command2 = "select count(*) from ?"

    I found this in

    http://qa.sqlservercentral.com/columnists/rsharma/countrecords.asp

    It only works on user (non-system) tables and set the "Execute Mode" to "Results in Text"

     

    Aunt Kathi Data Platform MVP
    Author of Expert T-SQL Window Functions
    Simple-Talk Editor

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply