Fastest Way to Retrieve Rowcount for a Table – SQL in Sixty Seconds #096


 

Whenever I am helping my clients with their SQL Server Performance Comprehensive Database Performance Health Check, every single time I get this question. What is the fastest way to retrieve rowcount for a table? 

Performance issues most of the time arises when there is a suboptimal code or table is huge and it is properly not maintained. Whenever I ask my clients about the rowcount in the table, they usually run the code something very similar to the following code.

SELECT COUNT(*) 
FROM TABLE WITH(NOLOCK)

I think it is very dangerous to run the code like above because it will do the complete table