Friday 27 April 2012

Sql Server–Row Count for All Tables

 

Tested on Sql Server 2008 and 2008 R2.

Code Snippet
  1. select SCHEMA_NAME(sys.tables.schema_id) as [Schema], sys.tables.name as [Table], sys.sysindexes.rowcnt as [Cnt]
  2. from sys.indexes
  3.     join sys.sysindexes
  4.         on sysindexes.id = sys.indexes.object_id
  5.             and sysindexes.indid = sys.indexes.index_id
  6.     join sys.tables
  7.         on sys.tables.object_id = sys.sysindexes.id
  8. where is_primary_key = 1
  9.     and sys.tables.type_desc = 'USER_TABLE'
  10. order by [Schema], [Table]

It is simple, isn’t it?

No comments:

Post a Comment