Select name and count(records) from all tables in DB

  • Hi all!

    I have a db with app. 500 tables.

    Many af them are empty, or has just a very few records.

    Now i need to make a script, that creates tablename, count(records table) for all tables in the db.

    sorted on count,name

    How to?

    Best regards

    Edvard Korsbæk

  • SELECT OBJECT_NAME(object_id) AS TableName, SUM(rows) AS Rows FROM sys.partitions

    WHERE index_id IN (0,1)

    AND OBJECTPROPERTY(object_id, 'IsMSShipped') = 0

    GROUP BY object_id

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Thanks as so many times before.

    I should document the tables to national achives in Denmark, and this answer makes it possible to ducument, that i need no documentation for app. 50 % of the tables..

    Best regards

    Edvard Korsbæk

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

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