Tuesday 17 January 2017

SQL Query to list number of records in each table in a database

SQL Query to list number of records in each table in a database

Description:

In this example we explain that how to get total number of record in each table in SQL Server or SQL Query to fetch the total number of record in each table in SQL Server. Sometime you have requirements like list the number of records in each table in a database so different query for different user like sql query that provide the row counts and table names in a database. Or how to fetch the row count for all tables in a SQL Server database.

Keeping track of your row counts can be very useful for budgeting and capacity planning.

Suppose I have 100 table in my SQL Server database and I want to fetch all the table that have more than 500 record in each table so in this situation below is the sql query useful for us.
Below is the query to get exact row counts for all tables in sql server
Query:

            SELECT o.NAME,
              i.rowcnt
            FROM sysindexes AS i
              INNER JOIN sysobjects AS o ON i.id = o.id
            WHERE i.indid <AND OBJECTPROPERTY(o.id, 'IsMSShipped') = 0 and  i.rowcnt >500

            ORDER BY o.NAME
This entry was posted in :

2 comments:

  1. Your blog is very well done, thus i got more information from your blog it is very well nice and interesting too.

    Web Design Company in Chennai

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete