Technical Article

Database count using system tables

,

An easy way to created a quick record count of all the tables within a sql server database.

USE DATABASENAME
select  
         tb.name as TableName
         ,max (p.rows) as RecordCount
  from sys.tables tb
 inner join sys.indexes i
 on tb.object_id = i.object_id
 and tb.type = 'U'
inner join sys.partitions p
on p.object_id = i.object_id
and p.index_id= i.index_id
group by tb.name
order by RecordCount

Rate

3 (1)

You rated this post out of 5. Change rating

Share

Share

Rate

3 (1)

You rated this post out of 5. Change rating