Row count for views and tables

  • Hi Friends

    Hope you doing well. I am in need to find the row count for all views and tables in a database in sql 2005 & 2008 version.I tried it is taking very long time to return the result Could you help in this.

    Cheers,

    vino

  • For tables you can query sys.partitions. The row count is in there (filter for index_id in 0,1). For views you'll have to run SELECT Count(*), the row counts aren't stored as they are just saved select statements, they don't store data.

    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
  • Hi,

    The sys.partitions table can be used for records count in a table.

    You can check article for more samples and sql scripts on SQL RowCount using sys.partitions

    Using sys.partitions view is actually very fast for this task instead of using select count(*) method

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

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