Click here to Skip to main content
Click here to Skip to main content

How Many Records Are There in your Database?

By , 20 Jul 2009
 

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)

About the Author

Md. Marufuzzaman
CEO
Bangladesh Bangladesh
Member
He is the founder & CEO of MNH Technologies and working for urban and rural sectors to improve people’s lifestyle, better medical facilities, education, social business etc. He has over ten years of professional experiences in design and developing Client-Server, Multi-Tier, Database, Web based business software solutions, Enterprise Applications, API, WebAPI, Google Analytics implementation, Add-In, Documentation & Technical Writing etc for Windows / Mac using Microsoft SQL Server, Oracle, MySql, PS, C#, VB.NET, ASP.NET, PHP, RoR, Visual Basic etc. He has also more than two years experience in Mobile-VAS (Platform Development).
 
He worked for various software development & technology consulting. His core focus on technologies to create dynamic data-driven systems that add value to your business and dynamic technology consulting that builds advanced solutions for the industries across the various vertices.
 
He also work as a Solution Architect at Dhrupadi Techno Consortium Limited (DTCL) and responsible for analyzing business requirements and offered optimum solutions (multiple options), which would address all current requirements, provide flexibility for future growth and allow smooth transition between old system and new system.
 
He graduated with honors from The University of Asia Pacific, in Computer Science and Engineering. He was awarded as “Most Valuable Professional” (MVP) at 2010 and 2011 by CodeProject.com and also selected as a Mentor of CodeProject.com
 
Specialties: Software Development Management, System Integration, Data Warehouse Architecture, Virtualization.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralMy vote of 5memberhadi552616 Aug '11 - 19:11 
GeneralRe: My vote of 5mvpMd. Marufuzzaman5 Oct '11 - 22:50 
GeneralMy vote of 5memberAslam_Iqbal13 Jan '11 - 3:20 
GeneralRe: My vote of 5mvpMd. Marufuzzaman5 Oct '11 - 22:51 
GeneralMy vote of 5memberTasnia.Maruf20 Sep '10 - 0:24 
GeneralRe: My vote of 5mvpMd. Marufuzzaman1 Oct '10 - 18:23 
GeneralMy vote of 1memberPSU Steve23 Jul '09 - 8:54 
GeneralRe: My vote of 1groupMd. Marufuzzaman26 Jul '09 - 5:13 
GeneralI think this just counts the number of rows in a specific index...memberJohn_Crocker20 Jul '09 - 21:59 
AnswerRe: I think this just counts the number of rows in a specific index...memberMd. Marufuzzaman21 Jul '09 - 0:19 
GeneralRe: I think this just counts the number of rows in a specific index...memberje_gonzalez21 Jul '09 - 18:53 
GeneralRe: I think this just counts the number of rows in a specific index...groupMd. Marufuzzaman26 Jul '09 - 5:14 

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

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