Question on Row Count

  • Why we will use sum(row_count) from sys.dm_db_partition_stats instead of using row_count from sys.dm_db_partition_stats because i verified both the results are same.

    Detailed:

    why we use the below query to get row count

    (SELECT Sum(row_count)

    FROM sys.dm_db_partition_stats

    WHERE OBJECT_ID = OBJECT_ID('testu'))

    instead of

    (SELECT (row_count)

    FROM sys.dm_db_partition_stats

    WHERE OBJECT_ID = OBJECT_ID('testu'))

  • are you testing this against a database with only one partition?

    I suspect the SUM is to account for databases with multiple partitions

  • I don't know how many paritions but thanks for ur reply

    So one Database can have multiple partitions ?

  • Your query is wrong. Add the predicate index_id IN (0,1) or you'll get multiples of the row count if there are any nonclustered indexes.

    One row per table, per index, per partition.

    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
  • Thank you

Viewing 5 posts - 1 through 4 (of 4 total)

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