In T-SQL usually we use the below query to get the total number of rows in a table
SELECT COUNT(*) FROM tblEmployeeMaster
There is another way to get the total number of rows in a table. But this is more efficient than the above one.
SELECT t.object_id ,t.Name,i.index_id,i.rows FROM sys.tables AS t INNER JOIN sys.partitions AS i
ON t.object_id = i.object_id WHERE i.index_id < 2 AND t.object_id=OBJECT_ID(‘tblEmployeeMaster’)
Of course, you can remove the condition “AND t.object_id=OBJECT_ID(‘tblEmployeeMaster’)” to view all the tables and their row count.
See the performance of the both queries using the Execution Plan
From the above execution plan you can see that Query 1 takes less execution cost than Query 2. So, Query 1 will give good performance than Query 2.

Posted by Getting the number of rows for each database and each table | Schmitt Blog on April 18, 2012 at 7:32 AM
[...] has a better performance than the “count(*)” query. If you want to know why look at http://asganesh.wordpress.com/2009/08/29/t-sql-row-count-in-a-table/ Share this:TwitterFacebookLike this:LikeBe the first to like this post. This entry was posted in [...]