Skip to content

Instantly share code, notes, and snippets.

@Warrenn
Created June 9, 2020 13:48
Show Gist options
  • Save Warrenn/795f0219b28897e454a372d5f1e3f1f5 to your computer and use it in GitHub Desktop.
Save Warrenn/795f0219b28897e454a372d5f1e3f1f5 to your computer and use it in GitHub Desktop.
fast count of rows
SELECT @count = SUM(p.rows)
FROM sys.partitions AS p
INNER JOIN sys.tables AS t
ON p.[object_id] = t.[object_id]
INNER JOIN sys.schemas AS s
ON t.[schema_id] = s.[schema_id]
WHERE p.index_id IN (0,1) -- heap or clustered index
AND t.name = N'tablename'
AND s.name = N'dbo';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment