dcsimg
LinkedIn
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Intermediate
Feb 19, 2020

Get All the Tables with a Count of Their Records

Get all the tables with a count of their records with the following query:

CREATE TABLE #Temp 
( 

TableName VARCHAR(MAX), 
Rows INT 
); 

EXEC sp_MSForEachTable @command1 = 'INSERT INTO #Temp(TableName, Rows) SELECT ''?'', 
COUNT(*) FROM ?' 

SELECT * FROM #Temp ORDER BY Temp.Rows DESC; 

DROP TABLE #Temp;
Hannes du Preez
 
Close Icon
Thanks for your registration, follow us on our social networks to keep up-to-date