0

I am working with SQL Server 2008 R2.

I have a table named punch with lot of rows. I want to know number of rows in this table but without doing a count. Is it possible? If yes then how?

Thanks

ChumboChappati
  • 1,442
  • 4
  • 18
  • 38

2 Answers2

3

Sql have a function for that

sp_spaceused <Tablename>;

enter image description here

Juan Carlos Oropeza
  • 47,252
  • 12
  • 78
  • 118
1

Here is one way.

select row_count
from sys.dm_db_partition_stats
where object_id = object_id('punch')
Sean Lange
  • 33,028
  • 3
  • 25
  • 40
  • this gives me 9 rows. Do I need to add all the values in those 9 rows to know the total number of rows in that table? – ChumboChappati Nov 05 '15 at 21:40
  • Yes that view gives you the row count for every partition in the table. It is very clearly stated right there in the documentation. https://msdn.microsoft.com/en-us/library/ms187737.aspx – Sean Lange Nov 05 '15 at 21:43
  • The values I get are 72215111, 131922313, 204137424, 72215111, 131922313, 72215111, 131922313, 72215111, 131922313. If I add them up the total is **1020687120**. – ChumboChappati Nov 05 '15 at 21:44
  • This should be filtered by correct index_id – sepupic Jan 17 '20 at 14:45