Quantcast
Channel: SQL Server Wiki
Viewing full articles (33 articles)
Browse article index

Count Rows in All Tables

$
0
0
Current Revision posted to SQL Server by Lars Astrom on 7/19/2013 1:49:42 PM

See Also: [[wiki:Main Page|Main_Page]] - [[wiki:Transact SQL Code Library|Transact SQL Code Library]] - [[wiki:Size Calculations|Size Calculations]]

This script counts the number of rows in all objects in the current database.

T-SQL Code

SELECT 

   [TableName] = so.name, 
   [RowCount] = MAX(si.rows) 

FROM 

   sysobjects so, 
   sysindexes si 

WHERE 

   so.xtype = 'U' 
   AND 
   si.id = OBJECT_ID(so.name) 

GROUP BY 

   so.name 

ORDER BY 

   1

Query Test Checklist

  • Works on SQL Server 2008: Yes
  • Works on SQL Server 2005: Yes
  • Works on SQL Server 2000: Yes
  • Works on Standard Edition: Yes
  • Works on case-sensitive servers: Yes


Viewing full articles (33 articles)
Browse article index

Latest Images

Trending Articles



Latest Images