Home > Database > MS SQL Server > Get record count of large or locked tables in MSSQL

Get record count of large or locked tables in MSSQL

Ever wondered why it takes so much time to get the count of rows in an SQL table with millions of records?

 

In case when the table is large and fragmented the select count(*) from large_table_name’ may take seconds to minutes to return an output. Re-indexing can also take up considerable amount of time.

 

System tables can come to the rescue in this case.

There is a system table that stores the live meta information of all the tables, it is sysindexes

To retrieve the count of rows from any table, please use the following query:

 

 

Also for small sized tables using ‘Select count(1) from small_table_name‘ is more effective and less resource intensive than using ‘select count(*) from small_table_name

 

Post comments if this helps

This Article is TAGGED in , , , , , , , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">