SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

Get your favorite SSC scripts directly in SSMS with the free SQL Scripts addin. Search for scripts directly from SSMS, and instantly access any saved scripts in your SSC briefcase from the favorites tab.
Download now (direct download link)

Get record count for a specific database

By James Rea,

I found it interesting to sometimes know how many records there are in my databases. This coding will allow you to count all of the records contained within any single user database you have created. It is very simple to switch databases to count (1 line of coding need be modified). You can also sort the results by either the record count or the table name.

This coding is a modification of a post I had found that would display all of the tables and their record counts. I found the original posting to also include other tables that may not hold as much relevance such as system tables, etc. You can view the original posting at: http://www.sqlservercentral.com/scripts/Miscellaneous/30324/

I have attempted to make it clear as to what is the original coding and what I had added, and what additional options you could look to use with this coding.

Total article views: 19456 | Views in the last 30 days: 78
Related Articles

Count all records the tables

Count all the records from the tables that exist in a database


Need DateTime format and count of records

Need DateTime format and count of records


How do I count Analysis Services Databases?

Counting Databases


Counting records over several tables

Wanting to count the number of records in each table after a certain date


Get record count for a all databases

This is an addition to Jim Rea's "Get record count for a specific database". I modified it to loop ...