Feb 232010
 

I have had to look this query up a few times, so I thought I would write about it here:

USE [DBInstanceName]
GO
SELECT  st.row_count as [Row Count]
FROM sys.dm_db_partition_stats st
WHERE index_id < 2
and OBJECT_NAME(OBJECT_ID)='TableName'

  • Alastair

    Not sure if I’d agree in all scenarios.

    A quick check on an execution plan on a randomly selected table gives me a lower cost on doing:

    select count(*) from [TableName]