/*
查询表中总行数
由于sys.dm_db_partition_stats并不是实时更新,所以数据并不能保证是完全准确的。
并且包含了所有分区的数据,2008以后sqlserver对单独的一个表也会认为是一个分区
*/
SELECT Object_schema_name(ddps.object_id) + '.'
       + Object_name(ddps.object_id) AS NAME,
       Sum(ddps.row_count)           AS row_count
FROM   sys.dm_db_partition_stats AS ddps
       INNER JOIN sys.indexes ix
               ON ix.object_id = ddps.object_id
                  AND ix.index_id = ddps.index_id
WHERE  ix.type_desc IN ( 'CLUSTERED', 'HEAP' )
       AND Objectproperty(ddps.object_id, 'IsMSShipped') = 0
GROUP  BY ddps.object_id
ORDER  BY row_count DESC