Saturday, 12 April 2014

Query to display total number of rows for each tables in a database - SQL


Following query displays the total number of rows for each table in a database.


  • Open SSMS
  • Select database
  • Execute the below Query:

             select sysobjects.name 'Table Name',rowcnt 'Total # Rows' from sysindexes 
             inner join  sysobjects on sysindexes.id= sysobjects.id
             where indid < 2
             and sysobjects.xtype='U'
            Order by 'Total # Rows' desc

The above query will return the list of all the tables in a database along with total numbers of rows in it.

No comments:

Post a Comment