1
Answer

Database list having table count is 0

Photo of krunal pande

krunal pande

7y
204
1
Hi team I have one table having name master_test in which there are 2 column database name and table name. In database name there are all database name of server and table name is rawdata in all database. Now I want list of database having rawdata table having no record (0 record). Please suggest simple way for the same Thanx & Regards, Krunal Pande

Answers (1)

0
Photo of Rupesh Kahane
NA 10.6k 866.8k 7y
Please run bellow script .
you will get all tables information with number of rows
(you can modify this according to your requirement)
  1. CREATE TABLE #counts  
  2. (  
  3.     table_name varchar(255),  
  4.     row_count int  
  5. )  
  6.   
  7. EXEC sp_MSForEachTable @command1='INSERT #counts (table_name, row_count) SELECT ''?'', COUNT(*) FROM ?'  
  8. SELECT table_name, row_count FROM #counts ORDER BY table_name, row_count DESC  
  9. DROP TABLE #counts