Wednesday, November 16, 2011

How to get the Total rows in the table?


Method 1 : SELECT COUNT(@@ROWCOUNT) FROM Products
Method 2 : SELECT COUNT (ProductID) FROM Products
Method 3 : SELECT OBJECT_NAME(id) AS [Table Name],rowcnt FROM SYSINDEXES
WHERE OBJECTPROPERTY(id,’isUserTable’)=1 AND indid < 2 ORDER BY rowcnt DESC
Method 4 : SELECT rowcnt FROM sysindexes WHERE id = OBJECT_ID(‘Products’) AND indid < 2
Method 5 : SELECT OBJECT_NAME(OBJECT_ID) TableName,row_count FROM sys.dm_db_partition_stats
WHERE object_id = object_id(‘Products’) AND index_id < 2