FASTER COUNT SQL SERVER DATABASE TABLE TOTAL ROWS


Introduction

In this article, We will see how to get faster count database table rows in SQL server.

Let's See

I have a database table name [tblProducts]. Usually, when we want to count the total row from any table, we use these SQL scripts. 

select COUNT(*) TotalRow from [dbo].[tblProducts]

Let’s try this way count total row for [tblProducts] table. When I execute my SQL scripts


We can see in the picture this table has a total of 34332534 rows and it takes 24 seconds for counting.
Well, Let's try another way. Now we will see after executing these scripts.

SELECT  rows TotalRow from sysindexes where id = Object_ID('tblProducts') and indid <2 code="">


After executing this SQL scripts we can see It takes only 0 seconds. This the way we can faster count our database table total rows.

Post a Comment

2 Comments

  1. Hello there- I'm trying to execute the query, but getting confused on 'tblProducts'. 'tblProducts' is it your table name ?

    ReplyDelete