dcsimg
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
May 30, 2019

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


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
 
Thanks for your registration, follow us on our social networks to keep up-to-date