{"id":271,"date":"2013-03-08T09:44:23","date_gmt":"2013-03-08T09:44:23","guid":{"rendered":"https:\/\/sqlserverlearner.azurewebsites.net\/2013\/03\/08\/how-to-get-number-of-rows-in-a-table-without-using-count-function\/"},"modified":"2013-03-08T09:44:23","modified_gmt":"2013-03-08T09:44:23","slug":"how-to-get-number-of-rows-in-a-table-without-using-count-function","status":"publish","type":"post","link":"https:\/\/sqlserverlearner.com\/2013\/03\/08\/how-to-get-number-of-rows-in-a-table-without-using-count-function\/","title":{"rendered":"How to get number of rows in a table without using count function"},"content":{"rendered":"
How to get number of rows in a table without using count function?<\/strong><\/p>\n In SQL Server you can get the approximate number of rows in the table using the below sample script.<\/p>\n [sql] DBCC UPDATEUSAGE (0, @tablename) SELECT [ROWS]
\nUSE AdventureWorks
\nGO
\nDECLARE @tablename AS sysname = ‘Production.Product’;<\/p>\n
\n WITH NO_INFOMSGS;<\/p>\n
\nFROM SYS.indexes AS IND
\n INNER JOIN
\n SYS.partitions AS PRT
\n ON IND.object_id = PRT.object_id
\n AND IND.index_id = PRT.index_id
\nWHERE IND.object_id = OBJECT_ID(@tablename)
\n AND IND.index_id <= 1;
\n[\/sql]<\/p>\n