Click here to Skip to main content
11,478,619 members (49,560 online)
Click here to Skip to main content

How Many Records Are There in your Database?

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

Introduction

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,,>
-- =============================================

SELECT SYS_OBJ.NAME AS "TABLE NAME"
     , SYS_INDX.ROWCNT AS "ROW COUNT"
FROM SYSOBJECTS SYS_OBJ, SYSINDEXES SYS_INDX

WHERE SYS_INDX.ID = SYS_OBJ.ID
  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,
 AND SYS_OBJ.NAME <> 'SYSDIAGRAMS'

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]
COMPUTE SUM(SYS_INDX.ROWCNT) 

GO

Note

[sysobjects]

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

[sys.sysindexes]

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

History

  • 20th July, 2009: Initial post

License

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

Share

About the Author

Md. Marufuzzaman
Architect
Bangladesh Bangladesh
A highly 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 codeproject.com and also selected as a mentor of codeproject.com. Published over 100 technical articles in various software development resource sites (i.e., codeprojetc.com, 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.
4.Etc.
Follow on   Twitter   LinkedIn

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    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 | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 20 Jul 2009
Article Copyright 2009 by Md. Marufuzzaman
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid