Click here to Skip to main content
12,818,050 members (38,668 online)
Click here to Skip to main content
Add your own
alternative version


46 bookmarked
Posted 20 Jul 2009

How Many Records Are There in your Database?

, 20 Jul 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
How many records are there in your database?


How many records are there in your database? You might be thinking that you need to write a gigantic SQL statement for that. This article will demonstrate to you, how easily you can do it.

Isn't it interesting? The following code will allow you to count all of the records contained within any single user database you have created.

Using the Code

To use this code is very simple. Just open a query analyzer, put the code into the SQL editor and run it. If you want, you can make it as StoredProcedure / view or whatever you want.

-- =============================================
-- Author:        <Author,,Md. Marufuzzaman>
-- Create date: <Create Date,,>
-- Description:    <Description,,>
-- =============================================


  AND INDID IN(0,1) --This specifies 'user' databases only
  AND XTYPE = 'U' --This omits the diagrams table of the database
--You may find other system tables will need to be omitted,

ORDER BY SYS_INDX.rowcnt DESC --I found it more useful to display 
--The following line adds up all the rowcount results and places
--the final result into a separate column [below the first resulting table]




Contains one row for each object (constraint, default, log, rule, stored procedure, and so on) created within a database.


Contains one row for each index and table in the current database. XML indexes are not supported in this view. Partitioned tables and indexes are not fully supported in this view; use the sys.indexes catalog view instead.

Reference: MSDN


  • 20th July, 2009: Initial post


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


About the Author

Md. Marufuzzaman
Bangladesh Bangladesh
A well experienced leader with successful track record of software development, product innovations, brand management and corporate communication etc. Some successful product innovations have also achieved and awards “Most Valuable Professional” (MVP) at 2010 and 2011 by and also selected as a mentor of Published over 100 technical articles in various software development resource sites (i.e.,, Microsoft MSDN, and IEEE & IBM (In progress)) and various IT Forums, Blogs etc.

Over ten years of professional experiences in ICT field having extensive experience in formulating corporate vision and long term strategy. Leading development related functions including design, development, services, data management and analytics, customer experience management, content services, digital analytics and optimization.

An individual with results-driven approach and relentless in pursuit of excellence from a business and organizational standpoint. Believes in transparency, commitment and teamwork.

Expertise: Software/Solution Architect, SaaS platform base application, Large scale win32/web based business software solutions, enterprise applications, integration, etc.

Technologies/Tools: Microsoft.Net version 05/08/10/12, Microsoft SQL Server version 7/2K/05/08/12 , Oracle version 10/11, MySql version 5.1, 5.5, PS2, Visual C#, R, VB.NET, ASP.NET, PHP, API, MVC, WebAPI , Add-In Visual Basic etc.,. I have also more than two years’ of strong experience in mobile-VAS (platform development).

Points of Interest: Technology and research & development especially focused on business functionalities and social business areas as well, few stuff including:

1.R&D on new techniques as required to increase business revenue.
2.Urban and rural sectors to improve people’s lifestyle, better medical facilities, education, social business etc., using innovative technical solutions.
3.Research and innovative product development.

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
hadi552616-Aug-11 20:11
memberhadi552616-Aug-11 20:11 
GeneralRe: My vote of 5 Pin
Md. Marufuzzaman5-Oct-11 23:50
mvpMd. Marufuzzaman5-Oct-11 23:50 
GeneralMy vote of 5 Pin
Aslam_Iqbal13-Jan-11 4:20
memberAslam_Iqbal13-Jan-11 4:20 
GeneralRe: My vote of 5 Pin
Md. Marufuzzaman5-Oct-11 23:51
mvpMd. Marufuzzaman5-Oct-11 23:51 
GeneralMy vote of 5 Pin
Tasnia.Maruf20-Sep-10 1:24
memberTasnia.Maruf20-Sep-10 1:24 
GeneralRe: My vote of 5 Pin
Md. Marufuzzaman1-Oct-10 19:23
mvpMd. Marufuzzaman1-Oct-10 19:23 
GeneralMy vote of 1 Pin
PSU Steve23-Jul-09 9:54
memberPSU Steve23-Jul-09 9:54 
GeneralRe: My vote of 1 Pin
Md. Marufuzzaman26-Jul-09 6:13
groupMd. Marufuzzaman26-Jul-09 6:13 
GeneralI think this just counts the number of rows in a specific index... Pin
John_Crocker20-Jul-09 22:59
memberJohn_Crocker20-Jul-09 22:59 
AnswerRe: I think this just counts the number of rows in a specific index... Pin
Md. Marufuzzaman21-Jul-09 1:19
memberMd. Marufuzzaman21-Jul-09 1:19 
GeneralRe: I think this just counts the number of rows in a specific index... Pin
je_gonzalez21-Jul-09 19:53
memberje_gonzalez21-Jul-09 19:53 
GeneralRe: I think this just counts the number of rows in a specific index... Pin
Md. Marufuzzaman26-Jul-09 6:14
groupMd. Marufuzzaman26-Jul-09 6:14 

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

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

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170308.1 | Last Updated 20 Jul 2009
Article Copyright 2009 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid