Click here to Skip to main content
Click here to Skip to main content
Go to top

Record Count of Tables in SQL Server

, 16 Aug 2011
Rate this:
Please Sign up or sign in to vote.
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

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

thatraja
Web Developer
India India
Programmer | Dude | ||||||
 
About him & his blog? check out here. Currently he's updating the site, he'll return soon there with more things*.
 
In Codeproject, he posted a blogpost & more than couple of Tip/Tricks, hope he'll write more soon.
 
Favorite techs are MVC, WCF, Mobile, HTML5, CSS3, jQuery, etc.,
 
His hobbies are watching movies, CP, being alone, etc., But now he's working on something*.
 
* - SCAMP???
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralReason for my vote of 5 Nice one.. My 5 PinmemberTejas_Vaishnav13-Nov-11 20:58 
GeneralReason for my vote of 5 good code to understand Pinmembersriram from Hyderabad16-Aug-11 2:01 
GeneralReason for my vote of 4 Nice query PinmemberDoncp19-Jul-10 10:51 
GeneralTo Mr.Md. Marufuzzaman Pinmemberthatraja19-Feb-10 17:28 
JokeThanks man PinmemberAngsuman Chakraborty14-Feb-10 22:10 
GeneralRe: Thanks man Pinmemberthatraja15-Feb-10 5:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140926.1 | Last Updated 16 Aug 2011
Article Copyright 2010 by thatraja
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid