Home > Development & Technical > Return total row number for each table in database with SQL Server 2005

Return total row number for each table in database with SQL Server 2005

Using SQL Server 2005 and a bit of good old T-SQL you can obtain the row count for all tables in your database with this handy piece of code …

SELECT    object_id,

          OBJECT_NAME(object_id)  AS  ObjectName,

          SUM (row_count)         AS  RowCnt

FROM      sys.dm_db_partition_stats

WHERE     index_id  <  2

AND       OBJECTPROPERTY(object_id, ‘IsUserTable’)  =  1

GROUP BY  object_id

 

Thanks to Ferry Nugraha for this code!

Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: