Recent Articles

Get Approximate Row Count Fast on SQL Server

Row count can be extremely long for very tables with thousands or millions of rows. SQL Server is already optimized to count from the index instead of counting from the data table, but the operation can still take seconds, if not minutes to complete. If you don't need the exact number of rows, you can use the following query to get an approximate row count quickly on SQL Server:

SELECT rowcnt FROM sys.sysindexes WHERE id = OBJECT_ID('TABLE_NAME') AND indid < 2

where TABLE_NAME is the name of your table.