List all tables and their Row Counts by a single query in a database?

Scenario:

After replication setup or reinitialization we need to check the  row counts of 2 databases in sql server2005 to verify the replication.

Solution:

By running below query ,we can able to find out tables and their corresponding row counts in a single database.

Select

 o.name as TableName,

 Max(i.rowcnt) as TotalRows

from

 sys.sysobjects o inner join sys.sysindexes i on o.id=i.id

-–Only User defined tables


 Where o.xtype='U'


Group by o.name

Comments

Popular posts from this blog

SSIS2008R2 Error: 0xC0209303 at Package:

SQL2008R2 Error: The remote copy of database "XXXXX" has not been rolled forward to a point in time that is encompassed in the local copy of the database log. (Microsoft SQL Server, Error: 1412)