MS SQL Tips & Tricks

How to get number of records in each table in database

To get record rumber from all tables in database You just need to execute script bellow:

SELECT sysobjects.name as TableName, 
	max(sysindexes.rows) AS TableRows
FROM sysindexes INNER JOIN sysobjects ON 
			sysindexes.id = sysobjects.id
WHERE sysobjects.xtype = 'U'
GROUP BY sysobjects.name
ORDER BY max(sysindexes.rows) DESC

There is an assumption made, that each table has at least one index created.


Learn more tricks

Add Comment

Comments

12th September 2021

Cialis

AwasmaB