How to perfom fast record count in Sql Server T-Sql

Scenario :  You have a table that has a lot of rows and you want to know the total number of rows.

Solution 1 :  The classic solution is SELECT COUNT(*) FROM TableName but this can take a while.

Solution 2 : The faster way to get the record count would be one of the choises below :

  1. SELECT SUM(1) FROM TableName
  2. SELECT COUNT(1) FROM TableName
  3. SELECT ROWS FROM SYSINDEXES WHERE OBJECT_NAME(ID)  = 'TableName' and indid<2
  4. EXEC SP_SPACEUSED 'TableName'
  5. DBCC  CHECKTABLE(''TableName)

Lucian Leonte

MCT, MCITP, MCTS

Powered by CodeReview – Let's make it Better!