65.9K
CodeProject is changing. Read more.
Home

Record Count of Tables in SQL Server

starIconstarIconstarIconstarIcon
emptyStarIcon
starIcon

4.86/5 (21 votes)

Feb 12, 2010

CPOL
viewsIcon

56356

downloadIcon

1

The below query can be used to get the record count of all tables in the current database.

The query below can be used to get the record count of all the tables in the current database.

Code

SELECT 
T.TABLE_NAME AS [TABLE NAME], MAX(I.ROWS) AS [RECORD COUNT]
FROM SYSINDEXES I, INFORMATION_SCHEMA.TABLES T
WHERE T.TABLE_NAME = OBJECT_NAME(I.ID)
      AND T.TABLE_TYPE = 'BASE TABLE'
GROUP BY T.TABLE_SCHEMA, T.TABLE_NAME

Result

Example output against Northwind database:

TABLE NAMERECORD COUNT
Categories8
CustomerCustomerDemo0
CustomerDemographics0
Customers91
Employees9
EmployeeTerritories49
Order Details2155
Orders830
Products97
Region4
Shippers3
Suppliers29
Territories53