Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to count empty tables in database?

Is there any way to count tables with no rows in my database with using T-SQL statement?

like image 352
Jan Remunda Avatar asked Jan 25 '10 13:01

Jan Remunda


1 Answers

There you go... using a derived table.

SELECT * FROM
(
 SELECT 
  [TableName] = so.name, 
  [RowCount] = MAX(si.rows) 
 FROM 
  sysobjects so, 
  sysindexes si 
 WHERE 
  so.xtype = 'U' 
  AND 
  si.id = OBJECT_ID(so.name) 
 GROUP BY 
  so.name 
) sub
WHERE sub.[RowCount] = 0
like image 98
kevchadders Avatar answered Oct 24 '22 10:10

kevchadders