Record Count of Tables in SQL Server
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 NAME | RECORD COUNT |
---|---|
Categories | 8 |
CustomerCustomerDemo | 0 |
CustomerDemographics | 0 |
Customers | 91 |
Employees | 9 |
EmployeeTerritories | 49 |
Order Details | 2155 |
Orders | 830 |
Products | 97 |
Region | 4 |
Shippers | 3 |
Suppliers | 29 |
Territories | 53 |