Retrieving All Tables and No. of Rows on Sql Server.

vishalneeraj-24503
Posted by vishalneeraj-24503 under Sql Server category on | Points: 40 | Views : 225
1ST Way:-
SELECT OBJECT_NAME(ID) As TableName, Rows As TotalRows
FROM SysIndexes WHERE IndID IN (0,1)
AND OBJECTPROPERTY(ID, 'IsUserTable') = 1
ORDER BY TableName;

2ND Way:-
SELECT OBJECT_NAME(Object_id) As TableName, SUM(Rows) As TotalRows
FROM sys.partitions
WHERE OBJECTPROPERTY(Object_id, 'IsUserTable') = 1 AND Index_ID IN (0,1)
GROUP BY OBJECT_NAME(Object_id)
ORDER BY TableName;

Comments or Responses

Login to post response