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.



